示例#1
0
    private void OnWindow(int windowID)
    {
        GUI.skin = KSPScienceSettings.getSkin();
        GUILayout.BeginArea(new Rect(10, 10, windowPosition.width - 10, windowPosition.height - 10));
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical(GUILayout.MaxWidth(240));
        GUILayout.Label("Experiment Filters");
        scrollPlanet = GUILayout.BeginScrollView(scrollPlanet);
        int  pressedCounter = 0;
        bool pressedlast    = (pressedCounter == pressedFilterId);
        bool pressed;

        pressed = GUILayout.Toggle(pressedlast, "All Experiments", "Button");
        if (pressed && !pressedlast)
        {
            pressedFilterId      = pressedCounter;
            selectedBody         = "All";
            selectedExperiments  = GetSelectedExperimentsByTypes(allExperimentTypes, dataOutputList);
            selectedExperiments2 = selectedExperiments;
            pressedPlanet        = -1;
        }

        foreach (string experimentType in allExperimentTypes)
        {
            pressedCounter++;
            pressedlast = (pressedCounter == pressedFilterId);
            pressed     = GUILayout.Toggle(pressedlast, experimentType, "Button");
            if (pressed && !pressedlast)
            {
                pressedFilterId      = pressedCounter;
                selectedBody         = experimentType;
                selectedExperiments  = GetSelectedExperimentsByType(experimentType);
                selectedExperiments2 = selectedExperiments;
                pressedPlanet        = -1;
            }
        }
        CelestialBody sun = FlightGlobals.Bodies[0];


        CelestialBody[] bodies = FlightGlobals.Bodies.ToArray();
        Array.Sort(bodies, delegate(CelestialBody body1, CelestialBody body2)
        {
            if (body2.referenceBody == body1 && body1 != sun)
            {
                return(-1);
            }
            if (body1.referenceBody == body2 && body2 != sun)
            {
                return(1);
            }
            if (body1.referenceBody == body2.referenceBody && body2.referenceBody != sun)
            {
                return(0);
            }
            return((sun.transform.position - body1.transform.position).magnitude.CompareTo((sun.transform.position - body2.transform.position).magnitude));
        });
        pressedCounter = 0;

        GUILayout.Space(20);
        foreach (CelestialBody body in bodies)
        {
            bool pressedlastPlanet = (pressedCounter == pressedPlanet);
            bool pressedP;
            if (body.referenceBody != sun)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(60);
            }
            pressedP = GUILayout.Toggle(pressedlastPlanet, body.name, "Button");
            if (pressedP && !pressedlastPlanet)
            {
                selectedBody         = body.name;
                selectedExperiments2 = GetSelectedExperiments(selectedBody, selectedExperiments);
                pressedPlanet        = pressedCounter;
            }
            if (body.referenceBody != sun)
            {
                GUILayout.EndHorizontal();
            }


            pressedCounter++;
        }
        GUILayout.EndScrollView();
        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();
        GUILayout.Label(selectedBody + " Experiments List");
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Sort by Name"))
        {
            if (lastsorted == 1)
            {
                selectedExperiments2.Sort(SortByNameD);
                lastsorted = 5;
            }
            else
            {
                selectedExperiments2.Sort(SortByName);
                lastsorted = 1;
            }
        }
        if (GUILayout.Button("Sort by Earned"))
        {
            if (lastsorted == 2)
            {
                selectedExperiments2.Sort(SortByEarnedD);
                lastsorted = 6;
            }
            else
            {
                selectedExperiments2.Sort(SortByEarned);
                lastsorted = 2;
            }
        }
        if (GUILayout.Button("Sort by Remaining"))
        {
            if (lastsorted == 3)
            {
                selectedExperiments2.Sort(SortByRemainD);
                lastsorted = 7;
            }
            else
            {
                selectedExperiments2.Sort(SortByRemain);
                lastsorted = 3;
            }
        }
        if (GUILayout.Button("Sort by Type"))
        {
            if (lastsorted == 4)
            {
                selectedExperiments2.Sort(SortByTypeD);
                lastsorted = 8;
            }
            else
            {
                selectedExperiments2.Sort(SortByType);
                lastsorted = 4;
            }
        }

        GUILayout.EndHorizontal();
        scrollPosition = GUILayout.BeginScrollView(scrollPosition);
        GUILayout.BeginHorizontal();
        GUILayout.Space(20);
        GUILayout.BeginVertical();
        GUILayout.Label("TYPE");
        GUIStyle styleNew  = KSPScienceSettings.getStyleSetting("LibraryNewExperiments");
        GUIStyle styleDone = KSPScienceSettings.getStyleSetting("LibraryDoneExperiments");

        foreach (Experiment experiment in selectedExperiments2)
        {
            if (experiment.earned == 0)
            {
                GUILayout.Label(experiment.FirstIdType, styleNew);
            }
            else
            {
                GUILayout.Label(experiment.FirstIdType, styleDone);
            }
        }
        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        GUILayout.Label("EARNED");
        foreach (Experiment experiment in selectedExperiments2)
        {
            if (experiment.earned == 0)
            {
                GUILayout.Label(experiment.earned.ToString(), styleNew);
            }
            else
            {
                GUILayout.Label(experiment.earned.ToString(), styleDone);
            }
        }
        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        GUILayout.Label("REMAINING");
        foreach (Experiment experiment in selectedExperiments2)
        {
            if (experiment.earned == 0)
            {
                GUILayout.Label(experiment.remain.ToString(), styleNew);
            }
            else
            {
                GUILayout.Label(experiment.remain.ToString(), styleDone);
            }
        }
        GUILayout.EndVertical();
        GUILayout.Space(20);
        GUILayout.BeginVertical();
        GUILayout.Label("Library");
        foreach (Experiment experiment in selectedExperiments2)
        {
            if (experiment.earned == 0)
            {
                GUILayout.Label(experiment.fullName, styleNew);
            }
            else
            {
                GUILayout.Label(experiment.fullName, styleDone);
            }
        }
        GUILayout.EndVertical();
        GUILayout.Space(20);

        GUILayout.EndHorizontal();
        GUILayout.EndScrollView();
        GUILayout.Space(20);
        GUILayout.EndVertical();
        GUILayout.Space(20);
        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        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));
    }
示例#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));
    }