Beispiel #1
0
        public void Awake()
        {
#if KSP1_4
            // 1.4 Addition
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }
#endif
            KCTDebug.Log("Awake called");
            KCT_GameStates.erroredDuringOnLoad.OnLoadStart();
            KCT_GameStates.PersistenceLoaded = false;

            instance = this;

            KCT_GameStates.settings.Load(); //Load the settings file, if it exists

            string SavedFile = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/KCT_Settings.cfg";
            if (!System.IO.File.Exists(SavedFile))
            {
                KCT_GameStates.firstStart = true;
            }

            if (KCT_PresetManager.Instance == null)
            {
                KCT_PresetManager.Instance = new KCT_PresetManager();
            }
            KCT_PresetManager.Instance.SetActiveFromSaveData();

            // Create events for other mods
            if (!KCT_Events.instance.createdEvents)
            {
                KCT_Events.instance.CreateEvents();
            }

            //Add the toolbar button
            if (ToolbarManager.ToolbarAvailable && ToolbarManager.Instance != null && KCT_GameStates.settings.PreferBlizzyToolbar)
            {
                KCTDebug.Log("Adding Toolbar Button");
                KCT_GameStates.kctToolbarButton = ToolbarManager.Instance.add("Kerbal_Construction_Time", "MainButton");
                if (KCT_GameStates.kctToolbarButton != null)
                {
                    if (KCT_PresetManager.PresetLoaded() && !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                    {
                        KCT_GameStates.kctToolbarButton.Visibility = new GameScenesVisibility(GameScenes.SPACECENTER);
                    }
                    else
                    {
                        KCT_GameStates.kctToolbarButton.Visibility = new GameScenesVisibility(new GameScenes[] { GameScenes.SPACECENTER, GameScenes.FLIGHT, GameScenes.TRACKSTATION, GameScenes.EDITOR });
                    }
                    KCT_GameStates.kctToolbarButton.TexturePath = KCT_Utilities.GetButtonTexture();
                    KCT_GameStates.kctToolbarButton.ToolTip     = "Kerbal Construction Time";
                    KCT_GameStates.kctToolbarButton.OnClick    += ((e) =>
                    {
                        KCT_GUI.ClickToggle();
                    });
                }
            }
            KCTDebug.Log("Awake finished");
        }
Beispiel #2
0
        public void IncrementProgress(double UTDiff)
        {
            // Don't progress blocked items
            if (GetBlockingTech(KCT_GameStates.TechList) != null)
            {
                return;
            }

            progress += BuildRate * UTDiff;
            if (isComplete || !KCT_PresetManager.Instance.ActivePreset.generalSettings.TechUnlockTimes)
            {
                if (KCT_GameStates.settings.ForceStopWarp && TimeWarp.CurrentRate > 1f)
                {
                    TimeWarp.SetRate(0, true);
                }
                if (protoNode == null)
                {
                    return;
                }
                EnableTech();
                KCT_GameStates.TechList.Remove(this);
                if (KCT_PresetManager.PresetLoaded() && KCT_PresetManager.Instance.ActivePreset.generalSettings.TechUpgrades)
                {
                    KCT_GameStates.MiscellaneousTempUpgrades++;
                }

                for (int j = 0; j < KCT_GameStates.TechList.Count; j++)
                {
                    KCT_GameStates.TechList[j].UpdateBuildRate(j);
                }
            }
        }
Beispiel #3
0
        public void Awake()
        {
            const string logBlockName = nameof(KerbalConstructionTime) + "." + nameof(Awake);

            using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All))
            {
                if (KCT_Utilities.CurrentGameIsMission())
                {
                    return;
                }
                GameStates.erroredDuringOnLoad.OnLoadStart();
                GameStates.PersistenceLoaded = false;

                instance = this;

                GameStates.settings.Load(); //Load the settings file, if it exists

                string SavedFile = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/KCT_Settings.cfg";
                if (!System.IO.File.Exists(SavedFile))
                {
                    GameStates.firstStart = true;
                }

                if (KCT_PresetManager.Instance == null)
                {
                    KCT_PresetManager.Instance = new KCT_PresetManager();
                }
                KCT_PresetManager.Instance.SetActiveFromSaveData();


                //Add the toolbar button
                if (ToolbarManager.ToolbarAvailable && ToolbarManager.Instance != null && GameStates.settings.PreferBlizzyToolbar)
                {
                    Log.Trace("Adding Toolbar Button");
                    GameStates.kctToolbarButton = ToolbarManager.Instance.add("Kerbal_Construction_Time", "MainButton");
                    if (GameStates.kctToolbarButton != null)
                    {
                        if (KCT_PresetManager.PresetLoaded() && !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                        {
                            GameStates.kctToolbarButton.Visibility = new GameScenesVisibility(GameScenes.SPACECENTER);
                        }
                        else
                        {
                            GameStates.kctToolbarButton.Visibility = new GameScenesVisibility(new GameScenes[] { GameScenes.SPACECENTER, GameScenes.FLIGHT, GameScenes.TRACKSTATION, GameScenes.EDITOR });
                        }
                        GameStates.kctToolbarButton.TexturePath = KCT_Utilities.GetButtonTexture();
                        GameStates.kctToolbarButton.ToolTip     = "Kerbal Construction Time";
                        GameStates.kctToolbarButton.OnClick    += ((e) =>
                        {
                            KCT_GUI.ClickToggle();
                        });
                    }
                }
            }
        }
Beispiel #4
0
        public void gameSceneEvent(GameScenes scene)
        {
            if (scene == GameScenes.MAINMENU)
            {
                KCT_GameStates.reset();
                KCT_GameStates.firstStart = false;
                InputLockManager.RemoveControlLock("KCTLaunchLock");
                KCT_GameStates.activeKSCName = "Stock";
                KCT_GameStates.ActiveKSC     = new KCT_KSC("Stock");
                KCT_GameStates.KSCs          = new List <KCT_KSC>()
                {
                    KCT_GameStates.ActiveKSC
                };
                KCT_GameStates.LastKnownTechCount = 0;

                KCT_GameStates.PermanentModAddedUpgradesButReallyWaitForTheAPI = 0;
                KCT_GameStates.TemporaryModAddedUpgradesButReallyWaitForTheAPI = 0;

                if (KCT_PresetManager.Instance != null)
                {
                    KCT_PresetManager.Instance.ClearPresets();
                    KCT_PresetManager.Instance = null;
                }

                return;
            }

            KCT_GameStates.MiscellaneousTempUpgrades = 0;

            if (KCT_PresetManager.PresetLoaded() && !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                return;
            }
            List <GameScenes> validScenes = new List <GameScenes> {
                GameScenes.SPACECENTER, GameScenes.TRACKSTATION, GameScenes.EDITOR
            };

            if (validScenes.Contains(scene))
            {
                TechDisableEventFinal();
            }

            if (HighLogic.LoadedScene == scene && scene == GameScenes.EDITOR) //Fix for null reference when using new or load buttons in editor
            {
                GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                EditorLogic.fetch.Unlock("KCTEditorMouseLock");
            }
        }
Beispiel #5
0
        internal KerbalConstructionTime()
        {
            instance = this;

            KCT_GameStates.settings.Load(); //Load the settings file, if it exists

            string SavedFile = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/KCT_Settings.cfg";

            if (!System.IO.File.Exists(SavedFile))
            {
                KCT_GameStates.firstStart = true;
            }

            if (KCT_PresetManager.Instance == null)
            {
                KCT_PresetManager.Instance = new KCT_PresetManager();
            }
            KCT_PresetManager.Instance.SetActiveFromSaveData();

            if (ToolbarManager.ToolbarAvailable && ToolbarManager.Instance != null && KCT_GameStates.settings.PreferBlizzyToolbar)
            {
                KCTDebug.Log("Adding Toolbar Button");
                KCT_GameStates.kctToolbarButton = ToolbarManager.Instance.add("Kerbal_Construction_Time", "MainButton");
                if (KCT_GameStates.kctToolbarButton != null)
                {
                    if (KCT_PresetManager.PresetLoaded() && !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                    {
                        KCT_GameStates.kctToolbarButton.Visibility = new GameScenesVisibility(GameScenes.SPACECENTER);
                    }
                    else
                    {
                        KCT_GameStates.kctToolbarButton.Visibility = new GameScenesVisibility(new GameScenes[] { GameScenes.SPACECENTER, GameScenes.FLIGHT, GameScenes.TRACKSTATION, GameScenes.EDITOR });
                    }
                    KCT_GameStates.kctToolbarButton.TexturePath = KCT_Utilities.GetButtonTexture();
                    KCT_GameStates.kctToolbarButton.ToolTip     = "Kerbal Construction Time";
                    KCT_GameStates.kctToolbarButton.OnClick    += ((e) =>
                    {
                        KCT_GUI.ClickToggle();
                    });
                }
            }
        }
Beispiel #6
0
        public void gameSceneEvent(GameScenes scene)
        {
            if (scene == GameScenes.MAINMENU)
            {
                KCT_GameStates.reset();
                KCT_GameStates.firstStart = false;
                KCT_Utilities.disableSimulationLocks();
                InputLockManager.RemoveControlLock("KCTLaunchLock");
                KCT_GameStates.activeKSCName = "Stock";
                KCT_GameStates.ActiveKSC     = new KCT_KSC("Stock");
                KCT_GameStates.KSCs          = new List <KCT_KSC>()
                {
                    KCT_GameStates.ActiveKSC
                };
                KCT_GameStates.EditorSimulationCount = 0;
                KCT_GameStates.LastKnownTechCount    = 0;

                KCT_GameStates.PermanentModAddedUpgradesButReallyWaitForTheAPI = 0;
                KCT_GameStates.TemporaryModAddedUpgradesButReallyWaitForTheAPI = 0;

                if (KCT_PresetManager.Instance != null)
                {
                    KCT_PresetManager.Instance.ClearPresets();
                    KCT_PresetManager.Instance = null;
                }

                return;
            }

            KCT_GameStates.MiscellaneousTempUpgrades = 0;

            /*if (HighLogic.LoadedScene == GameScenes.MAINMENU)
             * {
             *  if (scene == GameScenes.SPACECENTER)
             *  {
             *      KCT_PresetManager.Instance.FindPresetFiles();
             *      KCT_PresetManager.Instance.LoadPresets();
             *  }
             * }*/

            if (KCT_PresetManager.PresetLoaded() && !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                return;
            }
            List <GameScenes> validScenes = new List <GameScenes> {
                GameScenes.SPACECENTER, GameScenes.TRACKSTATION, GameScenes.EDITOR
            };

            if (validScenes.Contains(scene))
            {
                //Check for simulation save and load it.
                if (System.IO.File.Exists(KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/KCT_simulation_backup.sfs"))
                {
                    KCT_Utilities.LoadSimulationSave(false);
                }
                TechDisableEventFinal();
            }

            /*if (!HighLogic.LoadedSceneIsFlight && scene == GameScenes.FLIGHT && KCT_GameStates.flightSimulated) //Backup save at simulation start
             * {
             *  KCT_Utilities.MakeSimulationSave();
             * }*/

            if (HighLogic.LoadedScene == scene && scene == GameScenes.EDITOR) //Fix for null reference when using new or load buttons in editor
            {
                GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                EditorLogic.fetch.Unlock("KCTEditorMouseLock");
            }

            if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight)
            {
                KCT_GameStates.EditorSimulationCount = 0;
            }
        }