Ejemplo n.º 1
0
    public void GetSciData()
    {
        if (ResearchAndDevelopment.Instance == null)
        {
            return;
        }
        dataOutputList = new List <Experiment>();
        List <ScienceSubject> newExperiments = new List <ScienceSubject>();
        List <string>         exIds          = ResearchAndDevelopment.GetExperimentIDs();
        List <ScienceSubject> subjectslist   = ResearchAndDevelopment.GetSubjects();

        //I am glad this code runs only once! Too expensive!
        foreach (string id in exIds)
        {
            foreach (ExperimentSituations experimentSituation in Enum.GetValues(typeof(ExperimentSituations)))
            {
                foreach (CelestialBody body in FlightGlobals.Bodies)
                {
                    bool ocean = body.ocean;
                    if (ExperimentSituations.SrfSplashed == experimentSituation && !ocean)
                    {
                        continue;
                    }
                    if ((ExperimentSituations.FlyingHigh == experimentSituation || ExperimentSituations.FlyingLow == experimentSituation) && !body.atmosphere)
                    {
                        continue;
                    }
                    ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(id);
                    bool available = experiment.IsAvailableWhile(experimentSituation, body);
                    if (available)
                    {
                        bool shouldHaveBiome = experiment.BiomeIsRelevantWhile(experimentSituation);
                        if (shouldHaveBiome)
                        {
                            foreach (string biome in ResearchAndDevelopment.GetBiomeTags(body))
                            {
                                if (KSPScienceSettings.getBoolSetting("ShowOnlyKnownBiomes"))
                                {
                                    bool foundBiome = subjectslist.Any(subject => subject.id.Contains("@" + body.name) && subject.id.Contains(biome.Replace(" ", "")));
                                    if (!foundBiome)
                                    {
                                        continue;
                                    }
                                }
                                ScienceSubject ssj = new ScienceSubject(experiment, experimentSituation, body, biome);
                                if (id == "asteroidSample")
                                {
                                    ssj.scienceCap = experiment.scienceCap;
                                }
                                newExperiments.Add(ssj);
                            }
                            if (body.BiomeMap == null || body.BiomeMap.Attributes.Length == 0)
                            {
                                ScienceSubject ssj = new ScienceSubject(experiment, experimentSituation, body, "");
                                if (id == "asteroidSample")
                                {
                                    ssj.scienceCap = experiment.scienceCap;
                                }
                                newExperiments.Add(ssj);
                            }
                        }
                        else
                        {
                            ScienceSubject ssj = new ScienceSubject(experiment, experimentSituation, body, "");
                            if (id == "asteroidSample")
                            {
                                ssj.scienceCap = experiment.scienceCap;
                            }
                            newExperiments.Add(ssj);
                        }
                    }
                }
            }
        }


        foreach (ScienceSubject scienceSubject in subjectslist)
        {
            newExperiments.RemoveAll(subject => subject.id == scienceSubject.id);
            string     title      = scienceSubject.id;
            double     earned     = Math.Round(scienceSubject.science, 1);
            double     remain     = Math.Round(scienceSubject.scienceCap - scienceSubject.science, 1);
            string     body       = LibraryUtils.FindExperimentBody(scienceSubject.id.Split('@')[1]);
            string     type       = scienceSubject.id.Split('@')[0];
            Experiment experiment = new Experiment(title, earned, remain, body, type);
            dataOutputList.Add(experiment);
        }

        foreach (ScienceSubject newExperiment in newExperiments)
        {
            newExperiment.scientificValue = 1f;
            CelestialBody thisBody = FlightGlobals.Bodies.Find(celestialBody => newExperiment.id.Split('@')[1].StartsWith(celestialBody.name));
            Experiment    ex       = new Experiment(newExperiment.id, 0, Math.Round(newExperiment.scienceCap, 1), thisBody.name, newExperiment.id.Split('@')[0]);
            dataOutputList.Add(ex);
        }
        dataOutputList.Sort(SortByName);

        if (KSPScienceSettings.getBoolSetting("ShowOnlyKnownExperiments"))
        {
            allExperimentTypes = GetKnownExperimentTypes();
        }
        else
        {
            allExperimentTypes = GetAllExperimentTypes();
        }
    }
Ejemplo n.º 2
0
    private void OnWindow(int windowID)
    {
        GUI.skin = KSPScienceSettings.getSkin();
        //         GUILayout.BeginHorizontal();
        //         autoPauseOnNew = GUILayout.Toggle(autoPauseOnNew, "Auto Pause on new Science: " + autoPauseOnNew);
        //         GUILayout.EndHorizontal();
        scrollVector2 = GUILayout.BeginScrollView(scrollVector2);


        GUILayout.BeginHorizontal();
        for (int i = 0; i <= 6; i++)
        {
            GUILayout.BeginVertical();
            switch (i)
            {
            case 0:
                GUILayout.Label("ID");
                break;

            case 1:
                GUILayout.Label("Earned");
                break;

            case 2:
                GUILayout.Label("Max");
                break;

            case 3:
                GUILayout.Label("Remains");
                break;

            case 4:
                GUILayout.Label("OnShip");
                break;

            case 5:
                GUILayout.Label("NextExp");
                break;

            case 6:
                if (KSPScienceSettings.getBoolSetting("ShowDeployButton"))
                {
                    GUILayout.Label("Deploy");
                }
                break;
            }
            foreach (ExperimentView experimentView in Output)
            {
                if (experimentView.EarnedScience >= experimentView.FullScience && !experimentView.OnShip)
                {
                    continue;
                }
                GUIStyle style = new GUIStyle();
                if (experimentView.OnShip)
                {
                    style = KSPScienceSettings.getStyleSetting("MonitorOnShipExperiments");
                }
                else if (experimentView.EarnedScience > 0)
                {
                    style = KSPScienceSettings.getStyleSetting("MonitorKSCExperiments");
                }
                else
                {
                    style = KSPScienceSettings.getStyleSetting("MonitorNewExperiments");
                    if (OnShip.Exists(view => view.FullExperimentId == experimentView.FullExperimentId))
                    {
                        continue;
                    }
                }
                switch (i)
                {
                case 0:
                    GUILayout.Label(experimentView.FullExperimentId, style);
                    break;

                case 1:
                {
                    string strout = Math.Round(experimentView.EarnedScience, 1).ToString();
                    if (strout == "0")
                    {
                        strout = "-";
                    }
                    GUILayout.Label(strout, style);
                }
                break;

                case 2:
                {
                    string strout = Math.Round(experimentView.FullScience, 1).ToString();
                    if (strout == "0")
                    {
                        strout = "-";
                    }
                    GUILayout.Label(strout, style);
                }
                break;

                case 3:
                    double percent = (experimentView.FullScience - experimentView.EarnedScience) / experimentView.FullScience * 100;
                    if (experimentView.FullScience == 0)
                    {
                        GUILayout.Label("-", style);
                    }
                    else if (percent >= 30)
                    {
                        GUIStyle tmpstyle = style;
                        style = KSPScienceSettings.getStyleSetting("MonitorNewExperiments");
                        GUILayout.Label(Math.Round(percent) + "%", style);
                        style = tmpstyle;
                    }
                    else
                    {
                        GUILayout.Label(Math.Round(percent) + "%", style);
                    }
                    break;

                case 4:
                    GUILayout.Label(experimentView.OnShip ? "\u221a" : " ", style);
                    break;

                case 5:
                {
                    string strout = Math.Round(experimentView.NextExperimentScience, 1).ToString();
                    if (strout == "0")
                    {
                        strout = "-";
                    }
                    GUILayout.Label(strout, style);
                }
                break;

                case 6:
                {
                    if (KSPScienceSettings.getBoolSetting("ShowDeployButton"))
                    {
                        GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
                        buttonStyle.margin           = new RectOffset(0, 0, 0, 0);
                        buttonStyle.normal.textColor = style.normal.textColor;
                        if (experimentView.FullExperimentId.Split('@')[0] == "asteroidSample")
                        {
                            //ModuleAsteroid[] asteroids = FindObjectsOfType<ModuleAsteroid>();
                            //ModuleScienceContainer collector = FlightGlobals.ActiveVessel.FindPartModulesImplementing<ModuleScienceContainer>().First<ModuleScienceContainer>();
                            //will be added in next version.
                            GUILayout.Button("------", buttonStyle, GUILayout.Height(15));
                        }
                        else
                        {
                            bool foundFreeSpaceForExperiment = false;
                            ModuleScienceExperiment moduleScienceExperiment = null;
                            foreach (ModuleScienceExperiment _moduleScienceExperiment in FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleScienceExperiment>())
                            {
                                if (_moduleScienceExperiment.experimentID == experimentView.FullExperimentId.Split('@')[0])
                                {
                                    if (!_moduleScienceExperiment.Deployed && !_moduleScienceExperiment.Inoperable && _moduleScienceExperiment.GetScienceCount() == 0)
                                    {
                                        foundFreeSpaceForExperiment = true;
                                        moduleScienceExperiment     = _moduleScienceExperiment;
                                        break;
                                    }
                                }
                            }
                            if (foundFreeSpaceForExperiment)
                            {
                                if (GUILayout.Button("deploy", buttonStyle, GUILayout.Height(15)))
                                {
                                    moduleScienceExperiment.DeployExperiment();
                                }
                            }
                            else
                            {
                                GUILayout.Button("------", buttonStyle, GUILayout.Height(15));
                            }
                        }
                    }
                }
                break;
                }
                //                 if (autoPauseOnNew && style.normal.textColor == Color.green)
                //                 {
                //                     //activate pause
                //                     TimeWarp.SetRate(0, true);
                //                     FlightDriver.SetPause(true);
                //                 }
            }
            GUILayout.EndVertical();
        }
        GUILayout.EndHorizontal();

        GUILayout.EndScrollView();
        //GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        GUILayout.Space(20);
        GUILayout.EndHorizontal();
        GUILayout.Space(20);
        if (GUI.Button(new Rect(windowPosition.width - 42, 0, 21, 21), "S"))
        {
            KSPScienceSettings.Toggle();
        }
        if (GUI.Button(new Rect(windowPosition.width - 21, 0, 21, 21), "X"))
        {
            Hide();
        }
        if (GUI.RepeatButton(new Rect(windowPosition.width - 21, windowPosition.height - 21, 21, 21), "\u21d8"))
        {
            resizingWindow = true;
        }
        GUI.DragWindow(new Rect(0, 0, 10000, 20));
    }