Example #1
0
        //[KSPAction("SCIENCE")]
        //public void scienceee(KSPActionParam param)
        //{
        //    observation();
        //}

        //[KSPEvent(guiActive = true, guiName = "Observe", active = true)]
        public void observation()
        {
            if (storedData.Count > 0)
            {
                CactEyeGUI.DisplayText("Processor already contains experiment data!");
                return;
            }
            if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX)
            {
                CactEyeGUI.DisplayText("Science experiments unavailable in sandbox mode!");
                return;
            }

            var target = FlightGlobals.fetch.VesselTarget;

            if (target == null)
            {
                CactEyeGUI.DisplayText("You must select a target!");
                return;
            }

            if (target.GetType().Name == "CelestialBody" && techType == "Planetary")
            {
                CelestialBody targetBody = FlightGlobals.Bodies.Find(n => n.GetName() == target.GetName());

                string oBody = CactEyeVars.CheckOccult(targetBody);
                if (oBody != "")
                {
                    CactEyeGUI.DisplayText("Target is behind " + oBody + "!");
                    return;
                }
                else if (targetBody == FlightGlobals.Bodies[0])
                {
                    CactEyeGUI.DisplayText("Cannot target the sun!");
                    return;
                }
                else if (opticsModule.GetTargetPos(targetBody.transform.position, 500f) == new Vector3(-1, -1, 0))
                {
                    CactEyeGUI.DisplayText("Target not in telescope sights!");
                    return;
                }
                else if (opticsModule.fov > CactEyeVars.bodySize[targetBody] * 50f)
                {
                    CactEyeGUI.DisplayText("Telescope not zoomed in far enough!");
                    return;
                }
                else
                {
                    doScience(FlightGlobals.Bodies.Find(n => n.GetName() == target.GetName()));
                }
            }
            else if (target.GetType().Name == "Vessel" && techType == "Asteroid")
            {
                Vessel targetVessel = target.GetVessel();
                if (techType == "Asteroid" && targetVessel.vesselType == VesselType.SpaceObject && targetVessel.DiscoveryInfo.trackingStatus.Value == "Tracking")
                {
                    if (CactEyeVars.GetPlanetBody(vessel.mainBody) == FlightGlobals.Bodies[1])
                    {
                        string oBody = CactEyeVars.CheckOccult(targetVessel);
                        if (oBody != "")
                        {
                            CactEyeGUI.DisplayText("Target is behind " + oBody + "!");
                            return;
                        }
                        else if (opticsModule.GetTargetPos(targetVessel.GetWorldPos3D(), 500f) == new Vector3(-1, -1, 0))
                        {
                            CactEyeGUI.DisplayText("Target not in telescope sights!");
                            return;
                        }
                        else if (opticsModule.fov > 0.5f)
                        {
                            CactEyeGUI.DisplayText("Telescope not zoomed in far enough!");
                            return;
                        }
                        else
                        {
                            doScience(targetVessel);
                        }
                    }
                    else
                    {
                        CactEyeGUI.DisplayText("Telescope must be near Kerbin to perform asteroid experiment!");
                        return;
                    }
                }
                else
                {
                    CactEyeGUI.DisplayText("Target not valid!");
                    return;
                }
            }
            else if (techType == "Occultation")
            {
                CelestialBody planetBody = CactEyeVars.GetPlanetBody(vessel.mainBody);

                if (occType != "None")
                {
                    print(occTime - Planetarium.GetUniversalTime());
                    if (occTime - Planetarium.GetUniversalTime() < 60) //target time is 30 seconds before limit, experiment should be within 30 seconds before or after target
                    {
                        if (occType == "Asteroid" && target.GetType().Name == "Vessel")
                        {
                            Vessel targetVessel = target.GetVessel();
                            if (targetVessel == CactEyeVars.occultationExpAsteroids[planetBody])
                            {
                                string oBody = CactEyeVars.CheckOccult(targetVessel);
                                if (oBody != "")
                                {
                                    CactEyeGUI.DisplayText("Target is behind " + oBody + "!");
                                    return;
                                }
                                else if (opticsModule.GetTargetPos(targetVessel.GetWorldPos3D(), 500f) == new Vector3(-1, -1, 0))
                                {
                                    CactEyeGUI.DisplayText("Target not in telescope sights!");
                                    return;
                                }
                                else if (opticsModule.fov > 0.5f)
                                {
                                    CactEyeGUI.DisplayText("Telescope not zoomed in far enough!");
                                    return;
                                }
                                else
                                {
                                    doScience(targetVessel);
                                }
                            }
                            else
                            {
                                CactEyeGUI.DisplayText("Incorrect target!");
                                return;
                            }
                        }
                        else if (occType != "Asteroid" && target.GetType().Name == "CelestialBody")
                        {
                            CelestialBody targetBody = FlightGlobals.Bodies.Find(n => n.GetName() == target.GetName());

                            if (targetBody != CactEyeVars.occultationExpBodies[planetBody])
                            {
                                CactEyeGUI.DisplayText("Incorrect target!");
                                return;
                            }
                            string oBody = CactEyeVars.CheckOccult(targetBody);
                            if (oBody != "")
                            {
                                CactEyeGUI.DisplayText("Target is behind " + oBody + "!");
                                return;
                            }
                            else if (opticsModule.GetTargetPos(targetBody.transform.position, 500f) == new Vector3(-1, -1, 0))
                            {
                                CactEyeGUI.DisplayText("Target not in telescope sights!");
                                return;
                            }
                            else if (opticsModule.fov > CactEyeVars.bodySize[targetBody] * 50f)
                            {
                                CactEyeGUI.DisplayText("Telescope not zoomed in far enough!");
                                return;
                            }
                            else
                            {
                                doScience(FlightGlobals.Bodies.Find(n => n.GetName() == target.GetName()));
                            }
                        }
                    }
                    else
                    {
                        CactEyeGUI.DisplayText("Occultation experiment must be performed within thirty seconds of target time!");
                        return;
                    }
                }
                else
                {
                    CactEyeGUI.DisplayText("Occultation experiment not available!");
                    return;
                }
            }
            else
            {
                CactEyeGUI.DisplayText("Target not valid!");
                return;
            }
        }
Example #2
0
        private void mainGUI(int windowID)
        {
            if (procModule == null && pMList.Count != 0)
            {
                procModule = pMList[0];
            }

            GUILayout.BeginVertical(GUILayout.ExpandHeight(true));

            if (procModule != null)
            {
                if (opticsModule != null && tex != null)
                {
                    if (!opticsModule.isDamaged)
                    {
                        if (!opticsModule.isSmallOptics ^ opticsModule.smallApertureOpen)
                        {
                            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                            GUILayout.Label("Zoom");

                            //Formatting zoom amount
                            string zoom;
                            if (opticsModule.fov > 0.064)
                            {
                                zoom = "X " + string.Format("{0:##0.0}", 64 / opticsModule.fov);
                            }
                            else
                            {
                                zoom = "X " + string.Format("{0:0.00E+0}", (64 / opticsModule.fov));
                                int pow = int.Parse(zoom.Substring(zoom.Length - 1));
                                if (pow > 9)
                                {
                                    print("ERROR: Telescope zooms in more than 10^" + pow + "!!!");
                                }
                                zoom  = zoom.Replace("E+", "x10");
                                zoom  = zoom.Remove(zoom.Length - 1);
                                zoom += uPow[pow];
                            }

                            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperRight;
                            GUILayout.Label(zoom);

                            GUILayout.EndHorizontal();


                            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperCenter;
                            fov = GUILayout.HorizontalSlider(fov, 0f, 1f);
                            //print("minFOV: " + procModule.minFOV + " || ^1/3: " + Mathf.Pow(procModule.minFOV, 1f / 3f));
                            opticsModule.fov = 0.5f * Mathf.Pow(4f - fov * (4f - Mathf.Pow(procModule.minFOV, 1f / 3f)), 3);

                            GUILayout.EndHorizontal();


                            GUILayout.Space(texRect.height);
                            tex = opticsModule.outputTex;
                            GUI.Box(new Rect(texRect.xMin - 2, texRect.yMin - 2, texRect.width + 4, texRect.height + 4), "");
                            GUI.DrawTexture(texRect, tex);
                            //GUILayout.Box("", GUILayout.Width(texRect.width), GUILayout.Height(texRect.height));
                            GUI.DrawTexture(new Rect(texRect.xMin, texRect.yMax - 32f, 128f, 32f), preview);
                            GUI.DrawTexture(new Rect(texRect.xMin + (0.5f * texRect.width) - 64, texRect.yMin + (0.5f * texRect.height) - 64, 128, 128), crosshair);
                            if (timer < 5f)
                            {
                                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                                GUI.Label(new Rect(texRect.xMin, texRect.yMin, 480, 50), new GUIContent(dispText));
                            }

                            if (FlightGlobals.fetch.VesselTarget != null)
                            {
                                string  targetName = FlightGlobals.fetch.VesselTarget.GetName();
                                Vector2 vec        = opticsModule.GetTargetPos(FlightGlobals.fetch.VesselTarget.GetTransform().position, texRect.width);

                                if (vec.x > 16 && vec.y > 16 && vec.x < texRect.width - 16 && vec.y < texRect.height - 16)
                                {
                                    GUI.DrawTexture(new Rect(vec.x + texRect.xMin - 16, vec.y + texRect.yMin - 16, 32, 32), targetPointer);
                                    Vector2 size = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(targetName));
                                    if (vec.x > 0.5 * size.x && vec.x < texRect.width - (0.5 * size.x) && vec.y < texRect.height - 16 - size.y)
                                    {
                                        GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperCenter;
                                        GUI.Label(new Rect(vec.x + texRect.xMin - (0.5f * size.x), vec.y + texRect.yMin + 20, size.x, size.y), targetName);
                                    }
                                }

                                if (procModule.techType == "Planetary" && procModule.isActive && procModule.isFunctional)
                                {
                                    if (GUI.Button(new Rect(texRect.xMax - 36, texRect.yMax - 36, 32, 32), save))
                                    {
                                        DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName));
                                    }
                                }
                            }
                        }
                        else
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Label("FungEye optics aperture closed.");
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            GUILayout.Label("Note that you can never close the aperture again once you open them with these optics!");
                            GUILayout.EndHorizontal();
                        }
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Optics module has been damaged by the sun! Repair must be made to optics module during an EVA.");
                        //print("FONT SIZE: " + GUI.skin.GetStyle("Label").fontSize);
                        GUILayout.EndHorizontal();
                    }
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("No optics detected!");
                    GUILayout.EndHorizontal();
                }

                GUILayout.Space(10f);

                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter;
                string targetstring;
                if (FlightGlobals.fetch.VesselTarget == null)
                {
                    targetstring = "No target selected";
                }
                else
                {
                    targetstring = "Target: " + FlightGlobals.fetch.VesselTarget.GetName();
                }

                GUILayout.Label(targetstring, GUILayout.Height(30f), GUILayout.Width(370f));

                if (GUILayout.Button("Select Target", GUILayout.Height(30f)))
                {
                    targetOpen = !targetOpen;
                }

                GUILayout.EndHorizontal();

                GUILayout.Space(10f);

                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleLeft;
                GUILayout.Label("Processor: ", GUILayout.Width(100f), GUILayout.Height(30f));

                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter;
                if (GUILayout.Button(procModule.pName, GUILayout.Height(30f)))
                {
                    int pI = pMList.IndexOf(procModule) + 1;
                    if (pI > pMList.Count - 1)
                    {
                        procModule = pMList[0];
                    }
                    else
                    {
                        procModule = pMList[pI];
                    }
                }

                GUILayout.Space(15);
                GUILayout.Label(procModule.status, GUILayout.Height(30f));
                GUILayout.FlexibleSpace();
                if (procModule.isFunctional)
                {
                    if (GUILayout.Button(procModule.isActive ? "Disable" : "Activate", GUILayout.Height(30f), GUILayout.Width(80f)))
                    {
                        procModule.toggle(null);
                    }
                }

                GUILayout.EndHorizontal();

                if (procModule.isActive && procModule.isFunctional && HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("", GUILayout.Width(100f), GUILayout.Height(30f));

                    if (procModule.GetScienceCount() == 0)
                    {
                        if (GUILayout.Button("Make Observation", GUILayout.Height(30f)))
                        {
                            procModule.observation();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Review Data", GUILayout.Height(30f)))
                        {
                            procModule.eventReviewScience();
                        }
                        GUILayout.Space(80);
                        if (GUILayout.Button("Dump Data", GUILayout.Height(30f)))
                        {
                            procModule.eventReviewScience();
                        }
                    }

                    GUILayout.EndHorizontal();

                    if (procModule.techType == "Occultation")
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("", GUILayout.Width(100f), GUILayout.Height(30f));

                        CelestialBody planetBody = CactEyeVars.GetPlanetBody(FlightGlobals.ActiveVessel.mainBody);

                        if (planetBody != null)
                        {
                            if (!CactEyeVars.occultationExpTypes.ContainsKey(planetBody))
                            {
                                CactEyeVars.GenerateOccultationExp(planetBody);
                            }

                            if (CactEyeVars.occultationExpTypes[planetBody] == "Asteroid")
                            {
                                GUILayout.Label("Next occultation: " + CactEyeVars.occultationExpAsteroids[planetBody].vesselName + ", at " + CactEyeVars.GetOccultationExpTimeString(planetBody), GUILayout.Height(30f));
                            }
                            else
                            {
                                GUILayout.Label("Next occultation: " + CactEyeVars.occultationExpBodies[planetBody].bodyName + ", at " + CactEyeVars.GetOccultationExpTimeString(planetBody), GUILayout.Height(30f));
                            }

                            //I sure wish I could put a button here to auto create a KAC alarm. Hint hint TriggerAu - make a KAC wrapper!
                        }
                        else
                        {
                            GUILayout.Label("Occultation experiment not available in solar orbit!");
                        }

                        GUILayout.EndHorizontal();
                    }
                }

                if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX)
                {
                    GUILayout.FlexibleSpace();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Science experiments unavailable in sandbox mode!");
                    GUILayout.EndHorizontal();
                }

                if (gMList.Count != 0)
                {
                    GUILayout.FlexibleSpace();

                    GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                    GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleLeft;
                    GUILayout.Label("Gyro Speed: ", GUILayout.Width(100f), GUILayout.Height(30f));

                    GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter;
                    gSel = GUILayout.SelectionGrid(gSel, gModes, 3, GUILayout.Height(30f));

                    if (gSel != gSelSt)
                    {
                        if (gSel == 0)
                        {
                            foreach (CactEyeGyro gM in gMList)
                            {
                                gM.normScale(null);
                            }
                        }
                        if (gSel == 1)
                        {
                            foreach (CactEyeGyro gM in gMList)
                            {
                                gM.redScale(null);
                            }
                        }
                        if (gSel == 2)
                        {
                            foreach (CactEyeGyro gM in gMList)
                            {
                                gM.fineScale(null);
                            }
                        }

                        gSelSt = gSel;
                    }

                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("No processors detected!");
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();

            GUI.DragWindow();
            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
        }