Ejemplo n.º 1
0
        IEnumerator tryExit()
        {
            if (needToSavegame)
            {
                if (CanSavegame)
                {
                    if (GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE) != string.Empty)
                    {
                        saveDone = true;
                        ScreenMessages.PostScreenMessage(Localizer.Format("quickexit_gameSaved", RegisterToolbar.MOD), 5);
                        Log("Game saved.", "QExit");
                    }
                    else
                    {
                        count = 10;
                        Log("Can't save game.", "QExit");
                        ScreenMessages.PostScreenMessage(Localizer.Format("quickexit_cantSave", RegisterToolbar.MOD), 10);
                    }
                    if (HighLogic.LoadedSceneIsEditor)
                    {
                        List <Part> parts = EditorLogic.fetch.ship != null ? EditorLogic.fetch.ship.Parts : new List <Part>();

                        if (parts.Count > 0)
                        {
                            ShipConstruction.SaveShip(shipFilename);
                            Log("Ship saved.", "QExit");
                            ScreenMessages.PostScreenMessage(Localizer.Format("quickexit_shipSaved", RegisterToolbar.MOD), 5);
                        }
                    }
                }
                else
                {
                    count = 10;
                    ClearToSaveStatus clearToSaveStatus = FlightGlobals.ClearToSave();
                    string            _status           = FlightGlobals.GetNotClearToSaveStatusReason(clearToSaveStatus, string.Empty);
                    Log("Can't game saved: " + _status, "QExit");
                    ScreenMessages.PostScreenMessage(Localizer.Format("quickexit_cantSave", RegisterToolbar.MOD) + ": " + _status, 10);
                }
            }
            while (count >= 0)
            {
                yield return(new WaitForSecondsRealtime(1f));

                Log("Exit in " + count, "QExit");
                count--;
            }
            if (!IsTryExit)
            {
                Log("tryExit stopped", "QExit");
                yield break;
            }
            Application.Quit();
            Log("tryExit ended", "QExit");
        }
Ejemplo n.º 2
0
        IEnumerator tryExit()
        {
            if (needToSavegame)
            {
                if (CanSavegame)
                {
                    if (GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE) != string.Empty)
                    {
                        saveDone = true;
                        ScreenMessages.PostScreenMessage(string.Format("[{0}] Game saved.", MOD), 5);
                        Log("Game saved.", "QExit");
                    }
                    else
                    {
                        count = 10;
                        Log("Can't save game.", "QExit");
                        ScreenMessages.PostScreenMessage(string.Format("[{0}] Can't save game.", MOD), 10);
                    }
                    if (HighLogic.LoadedSceneIsEditor)
                    {
                        ShipConstruction.SaveShip(shipFilename);
                        Log("Ship saved.", "QExit");
                        ScreenMessages.PostScreenMessage(string.Format("[{0}] Ship saved.", MOD), 5);
                    }
                }
                else
                {
                    count = 10;
                    ClearToSaveStatus clearToSaveStatus = FlightGlobals.ClearToSave();
                    string            _status           = FlightGlobals.GetNotClearToSaveStatusReason(clearToSaveStatus, string.Empty);
                    Log("Can't game saved: " + _status, "QExit");
                    ScreenMessages.PostScreenMessage(string.Format("[{0}] Can't save game: {1}", MOD, _status.ToString()), 10);
                }
            }
            while (count >= 0)
            {
                yield return(new WaitForSecondsRealtime(1f));

                Log("Exit in " + count, "QExit");
                count--;
            }
            if (!IsTryExit)
            {
                Log("tryExit stopped", "QExit");
                yield break;
            }
            Application.Quit();
            Log("tryExit ended", "QExit");
        }
Ejemplo n.º 3
0
        IEnumerator tryExit()
        {
            Log.Info("tryExit");

            if (CanSavegame)
            {
                if (GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE) != string.Empty)
                {
                    //saveDone = true;
                    ScreenMessages.PostScreenMessage(Localizer.Format("pm_gameSaved", MOD), 5);
                    MyLog("Game saved.", "QExit");
                }
                else
                {
                    count = 10;
                    MyLog("Can't save game.", "QExit");
                    ScreenMessages.PostScreenMessage(Localizer.Format("pm_cantSave", MOD), 10);
                }
            }
            else
            {
                count = 10;
                ClearToSaveStatus clearToSaveStatus = FlightGlobals.ClearToSave();
                string            _status           = FlightGlobals.GetNotClearToSaveStatusReason(clearToSaveStatus, string.Empty);
                MyLog("Can't game saved: " + _status, "QExit");
                ScreenMessages.PostScreenMessage(Localizer.Format("pm_cantSave", MOD) + ": " + _status, 10);
            }

            while (count >= 0)
            {
                yield return(new WaitForSecondsRealtime(1f));

                MyLog("Exit in " + count, "QExit");
                count--;
            }
            Log.Info("tryExit, ready to exit");
            if (!IsTryExit)
            {
                MyLog("tryExit stopped", "QExit");
                yield break;
            }
            Log.Info("tryExit, before ApplicationQuit");
            Application.Quit();
            MyLog("tryExit ended", "QExit");
        }
Ejemplo n.º 4
0
        private void Update()
        {
            //destroy the old one
            VesselSwitching vesselSwitching = UnityEngine.Object.FindObjectOfType <VesselSwitching> ();

            if (vesselSwitching != null)
            {
                Destroy(vesselSwitching);
                Utils.Log("vesselSwitching destroyed.");
            }

            if (!MapView.MapIsEnabled)
            {
                if (!InputLockManager.IsLocked(ControlTypes.VESSEL_SWITCHING))
                {
                    if (!FlightDriver.Pause)
                    {
                        currentIndex = -1;
                        if (GameSettings.FOCUS_PREV_VESSEL.GetKeyDown())
                        {
                            if (HighLogic.CurrentGame != null && !HighLogic.CurrentGame.Parameters.Flight.CanSwitchVesselsNear)
                            {
                                PostMessage("Cannot switch vessels because it is disabled");
                                return;
                            }
                            if (HighLogic.LoadedSceneIsFlight)
                            {
                                CameraManager.Instance.SetCameraFlight();
                            }
                            this.vesselList.Clear();
                            currentIndex = FlightGlobals.Vessels.IndexOf(FlightGlobals.ActiveVessel);
                            do
                            {
                                currentIndex--;
                                if (currentIndex < 0)
                                {
                                    currentIndex += FlightGlobals.Vessels.Count;
                                }

                                currentVessel = FlightGlobals.Vessels [currentIndex];
                                if (currentVessel.loaded && currentVessel != FlightGlobals.ActiveVessel)
                                {
                                    //only allow switching to non-creature vessels
                                    if (!(currentVessel.rootPart is CreaturePart))
                                    {
                                        this.vesselList.Add(currentVessel);
                                    }
                                }
                            }while(currentVessel != FlightGlobals.ActiveVessel);
                        }
                        if (GameSettings.FOCUS_NEXT_VESSEL.GetKeyDown())
                        {
                            if (HighLogic.CurrentGame != null && !HighLogic.CurrentGame.Parameters.Flight.CanSwitchVesselsNear)
                            {
                                PostMessage("Cannot switch vessels because it is disabled");
                                return;
                            }
                            if (HighLogic.LoadedSceneIsFlight)
                            {
                                CameraManager.Instance.SetCameraFlight();
                            }
                            this.vesselList.Clear();
                            currentIndex = FlightGlobals.Vessels.IndexOf(FlightGlobals.ActiveVessel);
                            do
                            {
                                currentIndex++;
                                if (currentIndex >= FlightGlobals.Vessels.Count)
                                {
                                    currentIndex = 0;
                                }

                                currentVessel = FlightGlobals.Vessels [currentIndex];
                                if (currentVessel.loaded && currentVessel != FlightGlobals.ActiveVessel)
                                {
                                    //only allow switching to non-creature vessels
                                    if (!(currentVessel.rootPart is CreaturePart))
                                    {
                                        this.vesselList.Add(currentVessel);
                                    }
                                }
                            }while(currentVessel != FlightGlobals.ActiveVessel);
                        }
                        if (currentIndex != -1)
                        {
                            if (vesselList.Count <= 0)
                            {
                                PostMessage("No nearby objects to focus. Use the Map View to select distant ones.");
                            }
                            else
                            {
                                ClearToSaveStatus status = FlightGlobals.ClearToSave();
                                foreach (var vessel in vesselList)
                                {
                                    if (vessel.packed)
                                    {
                                        if (status != ClearToSaveStatus.CLEAR)
                                        {
                                            continue;
                                        }
                                    }
                                    FlightGlobals.ForceSetActiveVessel(vessel);
                                    FlightInputHandler.ResumeVesselCtrlState(vessel);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }