Example #1
0
        void Update()
        {
            // We don't want to do anything if we aren't simming
            if (KRASHShelter.persistent.shelterSimulationActive)
            {
                // Don't allow any of the recovery buttons to be used
                //	AltimeterSliderButtons _Recovery_button = (AltimeterSliderButtons)GameObject.FindObjectOfType (typeof(AltimeterSliderButtons));
                if (_Recovery_button == null)
                {
                    _Recovery_button = (AltimeterSliderButtons)GameObject.FindObjectOfType(typeof(AltimeterSliderButtons));
                }
                if (_Recovery_button != null && _Recovery_button.slidingTab.enabled)
                {
                    _Recovery_button.hoverArea                    = new XSelectable();
                    _Recovery_button.slidingTab.enabled           = false;
                    _Recovery_button.spaceCenterButton.enabled    = false;
                    _Recovery_button.vesselRecoveryButton.enabled = false;
                    Log.Info("Recovery locked");
                }


                if (KRASHShelter.instance.simPauseMenuInstance == null)
                {
                    Log.Info("FlightModule.Update KRASH.simPauseMenuInstance == null");
                    return;
                }
                if (KRASHShelter.instance == null)
                {
                    Log.Info("FlightModule.Update KRASH.instance == null");
                    return;
                }
                //Log.Info ("jbb PauseMenu.isOpen: " + PauseMenu.isOpen.ToString ());
                //Log.Info ("KRASHShelter.instance.simPauseMenuInstance.isOpen: " + KRASHShelter.instance.simPauseMenuInstance.isOpen.ToString ());

                bool b;
                try
                {
                    b = FlightResultsDialog.isDisplaying;
                }
                catch (Exception)
                {
                    Log.Info("FlightResultsDialog.isDisplaying exception");
                    b = false;
                }
                if (b)
                {
                    FlightResultsDialog.showExitControls   = false;
                    FlightResultsDialog.allowClosingDialog = true;
                    FlightResultsDialog.Display("Simulation ended!");
                }


                // Hide the vanilla pause menu.
                Log.Info("Checking PauseMenu");
                Log.Info("PauseMenu.isOpen: " + PauseMenu.isOpen.ToString());
                if (PauseMenu.isOpen)
                {
                    PauseMenu.Close();
                    pauseCnt = 1;
                }

                // Check for pause keypress
                //pauseCnt++;
                if (/* GameSettings.PAUSE.GetKeyDown() && */ pauseCnt != 0 && closeCnt == 0)
                {
                    Log.Info("GetKeyDown    menu.isOpen: " + KRASHShelter.instance.simPauseMenuInstance.isOpen);
                    if (GameSettings.PAUSE.GetKeyDown())
                    {
                        pauseCnt = 0;
                        Log.Info("GameSettings.PAUSE.GetKeyDown");
                    }
                    switch (KRASHShelter.instance.simPauseMenuInstance.isOpen)
                    {
                    case false:
                        if (pauseCnt == 1)
                        {
                            KRASHShelter.instance.simPauseMenuInstance.Display();
                            pauseCnt = 2;
                        }
                        break;

                    case true:
                        if (pauseCnt == 0)
                        {
                            Log.Info("menu.Close");
                            KRASHShelter.instance.simPauseMenuInstance.Close();
                            Log.Info("After close simPauseMenuInstance, PauseMenu.isOpen: " + PauseMenu.isOpen.ToString());
                            pauseCnt = 0;
                            closeCnt = 1;
                        }
                        break;
                    }
                }
                else
                {
                    // The wierd issue changed from 1.1.3 to 1.2, now, it pauses for 7-10 tics after unpausing
                    if (closeCnt > 0 && closeCnt++ < 20)
                    {
                        FlightDriver.SetPause(false);
                        PauseMenu.Close();
                        pauseCnt = 0;
                    }
                    else
                    {
                        closeCnt = 0;
                    }
                    // This is to get around a wierd issue where the game unpauses
                    // for about 7-10 tics after PauseMenu.Close() is called.
                    // if (KRASHShelter.instance.simPauseMenuInstance.isOpen && pauseCnt < 20 /*&& FlightDriver.Pause */)
                    //     FlightDriver.SetPause(true);
                }
            }
        }
Example #2
0
        void Update()
        {
            // We don't want to do anything if we aren't simming
            if (KRASHShelter.persistent.shelterSimulationActive)
            {
#if true
                if (HighLogic.CurrentGame.Parameters.CustomParams<KRASH_Settings>().wireframes)
                {
                    if (!wireFrameAdded)
                    {
                        wireFrameAdded = true;
                        Log.Info("Adding wireframe");
                        cams = Camera.allCameras;

                        for (int i = 0; i < cams.Length; i++)
                        {
                            if (cams[i].name == "Camera 00")
                            {
                                nearCamera = cams[i];
                            }
                            if (cams[i].name == "Camera 01")
                            {
                                //cams [i].renderingPath=RenderingPath.DeferredShading;
                                farCamera = cams[i];
                                //cams [i].enabled=false;

                            }
                            if (cams[i].name == "Camera ScaledSpace")
                            {
                                //cams [i].renderingPath=RenderingPath.DeferredShading;
                                scaledSpaceCamera = cams[i];
                            }
                        }
                        nearCamera.gameObject.AddComponent(typeof(WireFrame));
                        // farCamera.gameObject.AddComponent(typeof(WireFrame));
                        // scaledSpaceCamera.gameObject.AddComponent(typeof(WireFrame));
#if false
                        // Camera.main.gameObject.AddComponent(typeof(Wireframe));
                      
                    var v = FlightGlobals.ActiveVessel;

                    foreach (var p in v.parts)
                    {
                        
                        var mf = p.FindModelComponents<MeshFilter>();
                        var smr = p.FindModelComponents<SkinnedMeshRenderer>();

                        //  if (p.partTransform.GetComponent<MeshFilter>() || p.partTransform.GetComponent<SkinnedMeshRenderer>())
                        if ((mf != null && mf.Count > 0) || (smr != null && smr.Count > 0))
                        {
                            Log.Info("Wireframe added to part: " + p.partInfo.name);
                            // Add a WireFrame object to it.
                           // WireFrame added = p.gameObject.AddComponent<WireFrame>();

                          

                        }

                    }
#endif
                    }
#endif
                }
                // Don't allow any of the recovery buttons to be used
                //	AltimeterSliderButtons _Recovery_button = (AltimeterSliderButtons)GameObject.FindObjectOfType (typeof(AltimeterSliderButtons));
                if (_Recovery_button == null)
                {
                    _Recovery_button = (AltimeterSliderButtons)GameObject.FindObjectOfType(typeof(AltimeterSliderButtons));
                }
                if (_Recovery_button != null && _Recovery_button.slidingTab.enabled)
                {
                    _Recovery_button.hoverArea = new XSelectable();
                    _Recovery_button.slidingTab.enabled = false;
                    _Recovery_button.spaceCenterButton.enabled = false;
                    _Recovery_button.vesselRecoveryButton.enabled = false;
                    Log.Info("Recovery locked");
                }


                if (KRASHShelter.instance.simPauseMenuInstance == null)
                {
                    Log.Info("FlightModule.Update KRASH.simPauseMenuInstance == null");
                    return;
                }
                if (KRASHShelter.instance == null)
                {
                    Log.Info("FlightModule.Update KRASH.instance == null");
                    return;
                }
                //Log.Info ("jbb PauseMenu.isOpen: " + PauseMenu.isOpen.ToString ());
                //Log.Info ("KRASHShelter.instance.simPauseMenuInstance.isOpen: " + KRASHShelter.instance.simPauseMenuInstance.isOpen.ToString ());

                bool b;
                try
                {
                    b = FlightResultsDialog.isDisplaying;
                }
                catch (Exception)
                {
                    Log.Info("FlightResultsDialog.isDisplaying exception");
                    b = false;
                }
                if (b)
                {
                    FlightResultsDialog.showExitControls = false;
                    FlightResultsDialog.allowClosingDialog = true;
                    FlightResultsDialog.Display("Simulation ended!");
                }


                // Hide the vanilla pause menu.
                Log.Info("Checking PauseMenu");
                Log.Info("PauseMenu.isOpen: " + PauseMenu.isOpen.ToString());
                if (PauseMenu.isOpen)
                {
                    PauseMenu.Close();
                    pauseCnt = 1;
                }

                // Check for pause keypress
                //pauseCnt++;
                if (/* GameSettings.PAUSE.GetKeyDown() && */ pauseCnt != 0 && closeCnt == 0)
                {
                    Log.Info("GetKeyDown    menu.isOpen: " + KRASHShelter.instance.simPauseMenuInstance.isOpen);
                    if (GameSettings.PAUSE.GetKeyDown())
                    {
                        pauseCnt = 0;
                        Log.Info("GameSettings.PAUSE.GetKeyDown");
                    }
                    switch (KRASHShelter.instance.simPauseMenuInstance.isOpen)
                    {
                        case false:
                            if (pauseCnt == 1)
                            {
                                KRASHShelter.instance.simPauseMenuInstance.Display();
                                pauseCnt = 2;
                            }
                            break;
                        case true:
                            if (pauseCnt == 0)
                            {
                                Log.Info("menu.Close");
                                KRASHShelter.instance.simPauseMenuInstance.Close();
                                Log.Info("After close simPauseMenuInstance, PauseMenu.isOpen: " + PauseMenu.isOpen.ToString());
                                pauseCnt = 0;
                                closeCnt = 1;
                            }
                            break;
                    }
                }
                else
                {
                    // The wierd issue changed from 1.1.3 to 1.2, now, it pauses for 7-10 tics after unpausing
                    if (closeCnt > 0 && closeCnt++ < 20)
                    {
                        FlightDriver.SetPause(false);
                        PauseMenu.Close();
                        pauseCnt = 0;
                    }
                    else
                        closeCnt = 0;
                    // This is to get around a wierd issue where the game unpauses
                    // for about 7-10 tics after PauseMenu.Close() is called.
                    // if (KRASHShelter.instance.simPauseMenuInstance.isOpen && pauseCnt < 20 /*&& FlightDriver.Pause */)
                    //     FlightDriver.SetPause(true);
                }
            }
        }
        /// <summary>
        /// Draws the main mission window.
        /// Do not use currentMission.isDone or missionGoal.isDone(), use status instead!!!
        /// </summary>
        /// <param name="id">Identifier.</param>
        private void drawMainWindow(int id)
        {
            Status status = calculateStatus(currentMission, true, activeVessel);

            GUI.skin = HighLogic.Skin;
            GUILayout.BeginVertical();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Current budget: ", styleValueName);
            GUILayout.Label(manager.budget + CurrencySuffix, (manager.budget < 0 ? styleValueRed : styleValueGreen));
            GUILayout.EndHorizontal();

            // Show only when the loaded scene is an editor or a vessel is available and its situation is PRELAUNCH
            if (HighLogic.LoadedSceneIsEditor || status.onLaunchPad)
            {
                VesselResources res = vesselResources;
                showCostValue("Liquid fuel costs:", res.liquid(), styleValueGreen);
                showCostValue("Oxidizer costs:", res.oxidizer(), styleValueGreen);
                showCostValue("Monopropellant costs:", res.mono(), styleValueGreen);
                showCostValue("Solid fuel costs:", res.solid(), styleValueGreen);
                showCostValue("Xenon gas costs:", res.xenon(), styleValueGreen);
                showCostValue("Liquid engines: ", res.engine(), styleValueGreen);
                showCostValue("Crew insurance: ", res.crew(), styleValueGreen);
                showCostValue("Other resource costs:", res.materials(), styleValueGreen);
                showCostValue("Sum:", res.sum(), (res.sum() > manager.budget ? styleValueRed : styleValueGreen));
            }

            if (status.isClientControlled)
            {
                MissionStatus s = manager.getClientControlledMission(activeVessel);
                GUILayout.Label("This vessel is controlled by a client. Do not destroy this vessel! Fine: " + s.punishment + CurrencySuffix, styleWarning);
                GUILayout.Label("End of life in " + MathTools.formatTime(s.endOfLife - Planetarium.GetUniversalTime()));
            }
            else if (status.isOnPassiveMission)
            {
                MissionStatus s = manager.getPassiveMission(activeVessel);
                GUILayout.Label("This vessel is involved in a passive mission. Do not destroy this vessel! Fine: " + s.punishment + CurrencySuffix, styleWarning);
                GUILayout.Label("End of life in " + MathTools.formatTime(s.endOfLife - Planetarium.GetUniversalTime()));
            }

            GUILayout.Space(30);

            if (currentMission != null)
            {
                drawMission(currentMission, status);
            }
            else
            {
                drawPassiveMissions(manager.getActivePassiveMissions());

                if (GUILayout.Button("Configure"))
                {
                    settingsWindow(!showSettingsWindow);
                    resetCount = 0;
                }
            }

//            if (GUILayout.Button ("Draw landing area!", styleButton)) {
//                drawLandingArea = !drawLandingArea;
//            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            if (GUILayout.Button("Select mission package"))
            {
                createFileBrowser("Select mission from package", selectMissionPackage);
            }

            if (currentPackage != null)
            {
                if (GUILayout.Button("Open browser window"))
                {
                    packageWindow(true);
                }
            }

            if (currentMission != null)
            {
                if (GUILayout.Button("Deselect mission"))
                {
                    currentMission = null;
                }
            }

            if (status.missionIsFinishable)
            {
                if (GUILayout.Button("Finish the mission!"))
                {
                    manager.finishMission(currentMission, activeVessel, status.events);
                    hiddenGoals    = new List <MissionGoal> ();
                    currentMission = null;
                }
            }
            else
            {
                if (status.recyclable)
                {
                    VesselResources res = vesselResources;
                    showCostValue("Recyclable value: ", res.recyclable(activeVessel.Landed), styleCaption);
                    if (GUILayout.Button("Recycle and end flight!"))
                    {
                        manager.recycleVessel(activeVessel, res.recyclable(activeVessel.Landed));
                        FlightDriver.TerminateCurrentFlight();
                        FlightResultsDialog.showExitControls = true;
                        FlightResultsDialog.Display("Vessel has been recycled!");
                        recycled = true;
                    }
                }
            }

            GUILayout.EndVertical();
            GUI.DragWindow();
        }