Beispiel #1
0
        public static void reset()
        {
            const string logBlockName = nameof(GameStates) + "." + nameof(reset);

            using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All))
            {
                firstStart         = false;
                vesselErrorAlerted = false;

                PurchasedUpgrades = new List <int>()
                {
                    0, 0
                };
                targetedItem = null;
                KCT_GUI.ResetFormulaRateHolders();

                InventorySaleUpgrades = 0;
                InventorySalesFigures = 0;

                ExperimentalParts.Clear();
                MiscellaneousTempUpgrades = 0;

                BuildingMaxLevelCache.Clear();

                lastUT = 0;
            }
        }
Beispiel #2
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 #3
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
            LoadTree();
#if KSP1_4
            // 1.4 Addition
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }
#endif
            KCTDebug.Log("Reading from persistence.");
            KCT_GameStates.KSCs.Clear();
            KCT_GameStates.ActiveKSC = null;
            //KCT_Utilities.SetActiveKSC("Stock");
            KCT_GameStates.InitAndClearTechList();
            KCT_GameStates.TechUpgradesTotal = 0;
            KCT_GameStates.SciPointsTotal    = -1;

            KCT_DataStorage kctVS = new KCT_DataStorage();
            ConfigNode      CN    = node.GetNode(kctVS.GetType().Name);
            if (CN != null)
            {
                ConfigNode.LoadObjectFromConfig(kctVS, CN);
            }

            foreach (ConfigNode ksc in node.GetNodes("KSC"))
            {
                string  name       = ksc.GetValue("KSCName");
                KCT_KSC loaded_KSC = new KCT_KSC(name);
                loaded_KSC.FromConfigNode(ksc);
                if (loaded_KSC != null && loaded_KSC.KSCName != null && loaded_KSC.KSCName.Length > 0)
                {
                    loaded_KSC.RDUpgrades[1] = KCT_GameStates.TechUpgradesTotal;
                    if (KCT_GameStates.KSCs.Find(k => k.KSCName == loaded_KSC.KSCName) == null)
                    {
                        KCT_GameStates.KSCs.Add(loaded_KSC);
                    }
                }
            }
            KCT_Utilities.SetActiveKSCToRSS();


            ConfigNode tmp = node.GetNode("TechList");
            if (tmp != null)
            {
                foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
                {
                    KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem();
                    ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                    KCT_TechItem techItem = techStorageItem.ToTechItem();
                    techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                    KCT_GameStates.TechList.Add(techItem);
                }
            }

            KCT_GUI.CheckToolbar();
            KCT_GameStates.erroredDuringOnLoad.OnLoadFinish();
            //KerbalConstructionTime.DelayedStart();
        }
Beispiel #4
0
        private void OnGUI()
        {
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }


            try
            {
                if (!GUIExceptionThrown)
                {
                    KCT_GUI.SetGUIPositions();
                }
                else
                {
                    DateTime CurrentTime = DateTime.Now;
                    if (CurrentTime > GUIExceptionTime.AddSeconds(10))
                    {
                        GUIExceptionThrown = false;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                Log.Error(e.StackTrace);
                GUIExceptionThrown = true;
                GUIExceptionTime   = DateTime.Now;
            }
        }
Beispiel #5
0
 internal KerbalConstructionTime()
 {
     instance = this;
     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_GameStates.settings.enabledForSave)
             {
                 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.onClick();
             });
         }
     }
 }
Beispiel #6
0
 private void OnGUI()
 {
     if (KCT_Utilities.CurrentGameIsMission())
     {
         return;
     }
     KCT_GUI.SetGUIPositions();
 }
Beispiel #7
0
        public void GameSceneEvent(GameScenes scene)
        {
            KCT_GUI.HideAll();

            if (scene == GameScenes.MAINMENU)
            {
                KCTGameStates.Reset();
                KCTGameStates.IsFirstStart = false;
                InputLockManager.RemoveControlLock("KCTLaunchLock");
                KCTGameStates.ActiveKSCName = Utilities._defaultKscId;
                KCTGameStates.ActiveKSC     = new KSCItem(Utilities._defaultKscId);
                KCTGameStates.KSCs          = new List <KSCItem>()
                {
                    KCTGameStates.ActiveKSC
                };
                KCTGameStates.LastKnownTechCount = 0;

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

                return;
            }

            KCTGameStates.MiscellaneousTempUpgrades = 0;

            if (PresetManager.PresetLoaded() && !PresetManager.Instance.ActivePreset.GeneralSettings.Enabled)
            {
                return;
            }
            var 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");
            }

            if (scene == GameScenes.EDITOR && !HighLogic.LoadedSceneIsEditor)
            {
                KCT_GUI.FirstOnGUIUpdate = true;
            }
        }
Beispiel #8
0
 private void OnGUI()
 {
     /* 1.4 Addition
      * if (KCT_Utilities.CurrentGameIsMission())
      * {
      *  return;
      * }
      */
     KCT_GUI.SetGUIPositions();
 }
Beispiel #9
0
        public void HideAllGUIs()
        {
            const string logBlockName = nameof(KCTEvents) + "." + nameof(HideAllGUIs);

            using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All))
            {
                //KCT_GUI.hideAll();
                KCT_GUI.ClickOff();
            }
        }
Beispiel #10
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 #11
0
        public override void OnLoad(ConfigNode node)
        {
            KCTDebug.Log("Reading from persistence.");
            base.OnLoad(node);
            KCT_GameStates.KSCs.Clear();
            KCT_GameStates.ActiveKSC = null;
            //KCT_Utilities.SetActiveKSC("Stock");
            KCT_GameStates.TechList.Clear();
            KCT_GameStates.TechUpgradesTotal = 0;

            KCT_DataStorage kctVS = new KCT_DataStorage();
            ConfigNode      CN    = node.GetNode(kctVS.GetType().Name);

            if (CN != null)
            {
                ConfigNode.LoadObjectFromConfig(kctVS, CN);
            }

            foreach (ConfigNode ksc in node.GetNodes("KSC"))
            {
                string  name       = ksc.GetValue("KSCName");
                KCT_KSC loaded_KSC = new KCT_KSC(name);
                loaded_KSC.FromConfigNode(ksc);
                if (loaded_KSC != null && loaded_KSC.KSCName != null && loaded_KSC.KSCName.Length > 0)
                {
                    loaded_KSC.RDUpgrades[1] = KCT_GameStates.TechUpgradesTotal;
                    if (KCT_GameStates.KSCs.Find(k => k.KSCName == loaded_KSC.KSCName) == null)
                    {
                        KCT_GameStates.KSCs.Add(loaded_KSC);
                    }
                }
            }
            //KCT_Utilities.SetActiveKSCToRSS();
            KCT_Utilities.SetActiveKSC(KCT_GameStates.activeKSCName);


            ConfigNode tmp = node.GetNode("TechList");

            if (tmp != null)
            {
                foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
                {
                    KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem();
                    ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                    KCT_TechItem techItem = techStorageItem.ToTechItem();
                    techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                    KCT_GameStates.TechList.Add(techItem);
                }
            }
            //KCT_GameStates.ActiveKSC.AsConfigNode().Save(KSPUtil.ApplicationRootPath + "/KSC.node");

            KerbalConstructionTime.DelayedStart();
            KCT_GUI.CheckToolbar();
            KCT_GameStates.erroredDuringOnLoad.OnLoadFinish();
        }
Beispiel #12
0
        private void OnGUI()
        {
#if KSP1_4
            // 1.4 Addition
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }
#endif
            KCT_GUI.SetGUIPositions();
        }
Beispiel #13
0
 public void LaunchScreenOpenEvent(GameEvents.VesselSpawnInfo v)
 {
     if (!KCT_GUI.IsPrimarilyDisabled)
     {
         // PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Warning!", "To launch vessels you must first build them in the VAB or SPH, then launch them through the main KCT window in the Space Center!", "Ok", false, HighLogic.UISkin);
         //open the build list to the right page
         string selection = v.craftSubfolder.Contains("SPH") ? "SPH" : "VAB";
         KCT_GUI.ToggleVisibility(true);
         KCT_GUI.SelectList("");
         KCT_GUI.SelectList(selection);
         KCTDebug.Log($"Opening the GUI to the {selection}");
     }
 }
Beispiel #14
0
        private void OnGUI()
        {
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }

            if (!GuiInit)
            {
                KCT_GUI.InitBuildListVars();
                KCT_GUI.InitBuildPlans();
                GuiInit = true;
            }
            KCT_GUI.SetGUIPositions();
        }
Beispiel #15
0
        internal void OnGUI()
        {
            if (Utilities.CurrentGameIsMission())
            {
                return;
            }

            if (!_isGUIInitialized)
            {
                KCT_GUI.InitBuildListVars();
                KCT_GUI.InitBuildPlans();
                KCT_GUI.InitDevPartsToggle();
                _isGUIInitialized = true;
            }
            KCT_GUI.SetGUIPositions();
        }
Beispiel #16
0
        private void OnGUI()
        {
#if KSP1_4
            // 1.4 Addition
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }
#endif
            if (!GuiInit)
            {
                KCT_GUI.InitBuildListVars();
                KCT_GUI.InitBuildPlans();
                GuiInit = true;
            }
            KCT_GUI.SetGUIPositions();
        }
Beispiel #17
0
        public static void reset()
        {
            //firstStart = true;
            PartTracker           = new Dictionary <string, int>();
            PartInventory         = new Dictionary <string, int>();
            flightSimulated       = false;
            simulationInitialized = false;
            vesselDict            = new Dictionary <string, string>();
            BodiesVisited         = new List <string> {
                Planetarium.fetch.Home.name
            };
            simulationBody     = KCT_Utilities.GetBodyByName(BodiesVisited[0]);
            simulateInOrbit    = false;
            firstStart         = false;
            vesselErrorAlerted = false;

            /*  VABUpgrades = new List<int>() {0};
            *  SPHUpgrades = new List<int>() {0};
            *  RDUpgrades = new List<int>() {0, 0};*/
            PurchasedUpgrades = new List <int>()
            {
                0, 0
            };
            // LaunchPadReconditioning = null;
            targetedItem = null;
            KCT_GUI.ResetFormulaRateHolders();

            InventorySaleUpgrades = 0;
            InventorySalesFigures = 0;

            ExperimentalParts.Clear();
            MiscellaneousTempUpgrades = 0;


            lastUT = 0;
            //ActiveKSC = new KCT_KSC("Stock");
            //KSCs = new List<KCT_KSC>() {ActiveKSC};


            /* VABList = new List<KCT_BuildListVessel>();
             * VABWarehouse = new List<KCT_BuildListVessel>();
             * SPHList = new List<KCT_BuildListVessel>();
             * SPHWarehouse = new List<KCT_BuildListVessel>();
             * TechList = new List<KCT_TechItem>();*/
        }
Beispiel #18
0
        public void launchScreenOpenEvent(GameEvents.VesselSpawnInfo v)
        {
            const string logBlockName = nameof(KCTEvents) + "." + nameof(launchScreenOpenEvent);

            using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All))
            {
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    // PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Warning!", "To launch vessels you must first build them in the VAB or SPH, then launch them through the main KCT window in the Space Center!", "Ok", false, HighLogic.UISkin);
                    //open the build list to the right page
                    string selection = (v.craftSubfolder.Contains("SPH")) ? "SPH" : "VAB";
                    KCT_GUI.ClickOn();
                    KCT_GUI.SelectList("");
                    KCT_GUI.SelectList(selection);
                    Log.Trace("Opening the GUI to the " + selection);
                }
            }
        }
Beispiel #19
0
 public void launchScreenOpenEvent(GameEvents.VesselSpawnInfo v)
 {
     if (!KCT_GUI.PrimarilyDisabled)
     {
         //KCT_GameStates.flightSimulated = true; //no longer needed b/c that gui wont appear anymore!
         // PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Warning!", "To launch vessels you must first build them in the VAB or SPH, then launch them through the main KCT window in the Space Center!", "Ok", false, HighLogic.UISkin);
         //open the build list to the right page
         string selection = "VAB";
         if (v.craftSubfolder.Contains("SPH"))
         {
             selection = "SPH";
         }
         KCT_GUI.ClickOn();
         KCT_GUI.SelectList("");
         KCT_GUI.SelectList(selection);
         KCTDebug.Log("Opening the GUI to the " + selection);
     }
 }
Beispiel #20
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 #21
0
        public static void Reset()
        {
            IsFirstStart       = false;
            VesselErrorAlerted = false;

            IsSimulatedFlight = false;
            SimulationParams.Reset();

            PurchasedUpgrades = new List <int>()
            {
                0, 0
            };
            KCT_GUI.ResetFormulaRateHolders();

            MiscellaneousTempUpgrades = 0;

            BuildingMaxLevelCache.Clear();

            InitAndClearTechList();
        }
Beispiel #22
0
        public static void Reset()
        {
            IsFirstStart       = false;
            VesselErrorAlerted = false;

            PurchasedUpgrades = new List <int>()
            {
                0, 0
            };
            TargetedItem = null;
            KCT_GUI.ResetFormulaRateHolders();

            MiscellaneousTempUpgrades = 0;

            BuildingMaxLevelCache.Clear();

            LastUT = 0;

            InitAndClearTechList();
        }
Beispiel #23
0
        public static void reset()
        {
            firstStart         = false;
            vesselErrorAlerted = false;

            PurchasedUpgrades = new List <int>()
            {
                0, 0
            };
            targetedItem = null;
            KCT_GUI.ResetFormulaRateHolders();

            InventorySaleUpgrades = 0;
            InventorySalesFigures = 0;

            ExperimentalParts.Clear();
            MiscellaneousTempUpgrades = 0;

            BuildingMaxLevelCache.Clear();

            lastUT = 0;
        }
Beispiel #24
0
 private void RestoreAllGUIs()
 {
     KCT_GUI.RestorePrevUIState();
 }
Beispiel #25
0
 public void HideAllGUIs()
 {
     KCT_GUI.BackupUIState();
     KCT_GUI.ToggleVisibility(false);
 }
Beispiel #26
0
        public static void DrawPresetWindow(int windowID)
        {
            GUIStyle yellowText = new GUIStyle(GUI.skin.label);

            yellowText.normal.textColor = Color.yellow;

            if (WorkingPreset == null)
            {
                SetNewWorkingPreset(new KCT_Preset(KCT_PresetManager.Instance.ActivePreset), false); //might need to copy instead of assign here
                presetIndex = KCT_PresetManager.Instance.GetIndex(WorkingPreset);
            }

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();

            //preset selector
            GUILayout.BeginVertical();
            GUILayout.Label("Presets", yellowText, GUILayout.ExpandHeight(false));
            //preset toolbar in a scrollview
            presetScrollView = GUILayout.BeginScrollView(presetScrollView, GUILayout.Width(presetPosition.width / 6.0f)); //TODO: update HighLogic.Skin.textArea
            string[] presetShortNames = KCT_PresetManager.Instance.PresetShortNames(true);
            if (presetIndex == -1)
            {
                SetNewWorkingPreset(null, true);
            }
            if (changed && presetIndex < presetShortNames.Length - 1 && !KCT_Utilities.ConfigNodesAreEquivalent(WorkingPreset.AsConfigNode(), KCT_PresetManager.Instance.Presets[presetIndex].AsConfigNode())) //!KCT_PresetManager.Instance.PresetsEqual(WorkingPreset, KCT_PresetManager.Instance.Presets[presetIndex], true)
            {
                SetNewWorkingPreset(null, true);
            }

            int prev = presetIndex;

            presetIndex = GUILayout.SelectionGrid(presetIndex, presetShortNames, 1);
            if (prev != presetIndex) //If a new preset was selected
            {
                if (presetIndex != presetShortNames.Length - 1)
                {
                    SetNewWorkingPreset(new KCT_Preset(KCT_PresetManager.Instance.Presets[presetIndex]), false);
                }
                else
                {
                    SetNewWorkingPreset(null, true);
                }
            }

            //presetIndex = GUILayout.Toolbar(presetIndex, presetNames);

            GUILayout.EndScrollView();
            if (GUILayout.Button("Save as\nNew Preset", GUILayout.ExpandHeight(false)))
            {
                //create new preset
                SaveAsNewPreset(WorkingPreset);
            }
            if (WorkingPreset.AllowDeletion && presetIndex != presetShortNames.Length - 1 && GUILayout.Button("Delete Preset")) //allowed to be deleted and isn't Custom
            {
                DialogGUIBase[] options = new DialogGUIBase[2];
                options[0] = new DialogGUIButton("Delete File", DeleteActivePreset);
                options[1] = new DialogGUIButton("Cancel", DummyVoid);
                MultiOptionDialog dialog = new MultiOptionDialog("deletePresetPopup", "Are you sure you want to delete the selected Preset, file and all? This cannot be undone!", "Confirm Deletion", null, options);
                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, HighLogic.UISkin);
            }
            GUILayout.EndVertical();

            //Main sections
            GUILayout.BeginVertical();
            presetMainScroll = GUILayout.BeginScrollView(presetMainScroll);
            //Preset info section)
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            GUILayout.Label("Preset Name: " + WorkingPreset.name);
            GUILayout.Label("Description: " + WorkingPreset.description);
            GUILayout.Label("Author(s): " + WorkingPreset.author);
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            //Features section
            GUILayout.BeginVertical();
            GUILayout.Label("Features", yellowText);
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            WorkingPreset.generalSettings.Enabled                 = GUILayout.Toggle(WorkingPreset.generalSettings.Enabled, "Mod Enabled", HighLogic.Skin.button);
            WorkingPreset.generalSettings.BuildTimes              = GUILayout.Toggle(WorkingPreset.generalSettings.BuildTimes, "Build Times", HighLogic.Skin.button);
            WorkingPreset.generalSettings.ReconditioningTimes     = GUILayout.Toggle(WorkingPreset.generalSettings.ReconditioningTimes, "Launchpad Reconditioning", HighLogic.Skin.button);
            WorkingPreset.generalSettings.ReconditioningBlocksPad = GUILayout.Toggle(WorkingPreset.generalSettings.ReconditioningBlocksPad, "Reconditioning Blocks Pad", HighLogic.Skin.button);
            WorkingPreset.generalSettings.TechUnlockTimes         = GUILayout.Toggle(WorkingPreset.generalSettings.TechUnlockTimes, "Tech Unlock Times", HighLogic.Skin.button);
            WorkingPreset.generalSettings.KSCUpgradeTimes         = GUILayout.Toggle(WorkingPreset.generalSettings.KSCUpgradeTimes, "KSC Upgrade Times", HighLogic.Skin.button);
            WorkingPreset.generalSettings.TechUpgrades            = GUILayout.Toggle(WorkingPreset.generalSettings.TechUpgrades, "Upgrades From Tech Tree", HighLogic.Skin.button);
            WorkingPreset.generalSettings.SharedUpgradePool       = GUILayout.Toggle(WorkingPreset.generalSettings.SharedUpgradePool, "Shared Upgrade Pool (KSCSwitcher)", HighLogic.Skin.button);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Starting Upgrades:");
            WorkingPreset.generalSettings.StartingPoints = GUILayout.TextField(WorkingPreset.generalSettings.StartingPoints, GUILayout.Width(100));
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.EndVertical(); //end Features


            GUILayout.BeginVertical(); //Begin time settings
            GUILayout.Label("Time Settings", yellowText);
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Overall Multiplier: ");
            double.TryParse(OMultTmp = GUILayout.TextField(OMultTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.OverallMultiplier);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Build Effect: ");
            double.TryParse(BEffTmp = GUILayout.TextField(BEffTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.BuildEffect);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Inventory Effect: ");
            double.TryParse(IEffTmp = GUILayout.TextField(IEffTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.InventoryEffect);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Reconditioning Effect: ");
            double.TryParse(ReEffTmp = GUILayout.TextField(ReEffTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.ReconditioningEffect);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Max Reconditioning: ");
            double.TryParse(MaxReTmp = GUILayout.TextField(MaxReTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.MaxReconditioning);
            GUILayout.EndHorizontal();
            GUILayout.Label("Rollout-Reconditioning Split:");
            GUILayout.BeginHorizontal();
            //GUILayout.Label("Rollout", GUILayout.ExpandWidth(false));
            WorkingPreset.timeSettings.RolloutReconSplit = GUILayout.HorizontalSlider((float)Math.Floor(WorkingPreset.timeSettings.RolloutReconSplit * 100f), 0, 100) / 100.0;
            //GUILayout.Label("Recon.", GUILayout.ExpandWidth(false));
            GUILayout.EndHorizontal();
            GUILayout.Label((Math.Floor(WorkingPreset.timeSettings.RolloutReconSplit * 100)) + "% Rollout, " + (100 - Math.Floor(WorkingPreset.timeSettings.RolloutReconSplit * 100)) + "% Reconditioning");
            GUILayout.EndVertical();   //end time settings
            GUILayout.EndVertical();
            GUILayout.EndHorizontal(); //end feature/time setting split

            //begin formula settings
            GUILayout.BeginVertical();
            GUILayout.Label("Formula Settings (Advanced)", yellowText);
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Show/Hide Formulas"))
            {
                showFormula = !showFormula;
            }
            if (GUILayout.Button("View Wiki in Browser"))
            {
                Application.OpenURL("https://github.com/magico13/KCT/wiki");
            }
            GUILayout.EndHorizontal();

            if (showFormula)
            {
                //show half here, half on other side? Or all in one big list
                int textWidth = 350;
                GUILayout.BeginHorizontal();
                GUILayout.Label("NodeFormula: ");
                WorkingPreset.formulaSettings.NodeFormula = GUILayout.TextField(WorkingPreset.formulaSettings.NodeFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("UpgradeFunds: ");
                WorkingPreset.formulaSettings.UpgradeFundsFormula = GUILayout.TextField(WorkingPreset.formulaSettings.UpgradeFundsFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("UpgradeScience: ");
                WorkingPreset.formulaSettings.UpgradeScienceFormula = GUILayout.TextField(WorkingPreset.formulaSettings.UpgradeScienceFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("UpgradesForScience: ");
                WorkingPreset.formulaSettings.UpgradesForScience = GUILayout.TextField(WorkingPreset.formulaSettings.UpgradesForScience, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("ResearchFormula: ");
                WorkingPreset.formulaSettings.ResearchFormula = GUILayout.TextField(WorkingPreset.formulaSettings.ResearchFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("EffectivePart: ");
                WorkingPreset.formulaSettings.EffectivePartFormula = GUILayout.TextField(WorkingPreset.formulaSettings.EffectivePartFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("ProceduralPart: ");
                WorkingPreset.formulaSettings.ProceduralPartFormula = GUILayout.TextField(WorkingPreset.formulaSettings.ProceduralPartFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("BPFormula: ");
                WorkingPreset.formulaSettings.BPFormula = GUILayout.TextField(WorkingPreset.formulaSettings.BPFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("KSCUpgrade: ");
                WorkingPreset.formulaSettings.KSCUpgradeFormula = GUILayout.TextField(WorkingPreset.formulaSettings.KSCUpgradeFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Reconditioning: ");
                WorkingPreset.formulaSettings.ReconditioningFormula = GUILayout.TextField(WorkingPreset.formulaSettings.ReconditioningFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("BuildRate: ");
                WorkingPreset.formulaSettings.BuildRateFormula = GUILayout.TextField(WorkingPreset.formulaSettings.BuildRateFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("UpgradeReset: ");
                WorkingPreset.formulaSettings.UpgradeResetFormula = GUILayout.TextField(WorkingPreset.formulaSettings.UpgradeResetFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("InventorySale: ");
                WorkingPreset.formulaSettings.InventorySaleFormula = GUILayout.TextField(WorkingPreset.formulaSettings.InventorySaleFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("RolloutCosts: ");
                WorkingPreset.formulaSettings.RolloutCostFormula = GUILayout.TextField(WorkingPreset.formulaSettings.RolloutCostFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("IntegrationCosts: ");
                WorkingPreset.formulaSettings.IntegrationCostFormula = GUILayout.TextField(WorkingPreset.formulaSettings.IntegrationCostFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("IntegrationTime: ");
                WorkingPreset.formulaSettings.IntegrationTimeFormula = GUILayout.TextField(WorkingPreset.formulaSettings.IntegrationTimeFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("NewLaunchPadCost: ");
                WorkingPreset.formulaSettings.NewLaunchPadCostFormula = GUILayout.TextField(WorkingPreset.formulaSettings.NewLaunchPadCostFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("RushCost: ");
                WorkingPreset.formulaSettings.RushCostFormula = GUILayout.TextField(WorkingPreset.formulaSettings.RushCostFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("AirlaunchCost: ");
                WorkingPreset.formulaSettings.AirlaunchCostFormula = GUILayout.TextField(WorkingPreset.formulaSettings.AirlaunchCostFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("AirlaunchTime: ");
                WorkingPreset.formulaSettings.AirlaunchTimeFormula = GUILayout.TextField(WorkingPreset.formulaSettings.AirlaunchTimeFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
            GUILayout.EndVertical(); //end formula settings

            GUILayout.EndScrollView();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Save", GUILayout.ExpandWidth(false)))
            {
                KCT_PresetManager.Instance.ActivePreset = WorkingPreset;
                KCT_PresetManager.Instance.SaveActiveToSaveData();
                WorkingPreset = null;

                if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                {
                    KCT_Utilities.DisableModFunctionality();
                }
                //KCT_GameStates.settings.enabledForSave = KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled;
                KCT_GameStates.settings.MaxTimeWarp          = newTimewarp;
                KCT_GameStates.settings.ForceStopWarp        = forceStopWarp;
                KCT_GameStates.settings.DisableAllMessages   = disableAllMsgs;
                KCT_GameStates.settings.OverrideLaunchButton = overrideLaunchBtn;
                KCT_GameStates.settings.Debug         = debug;
                KCT_GameStates.settings.AutoKACAlarms = autoAlarms;
                // KCT_GameStates.settings.PreferBlizzyToolbar = useBlizzyToolbar;
                KCT_GameStates.settings.CheckForDebugUpdates = debugUpdateChecking;

                KCT_GameStates.settings.Save();
                showSettings = false;
                if (!PrimarilyDisabled && !showFirstRun)
                {
                    ResetBLWindow();

                    //if (KCT_Events.instance.KCTButtonStock != null)
                    //    KCT_Events.instance.KCTButtonStock.SetTrue();
                    if (KCT_GameStates.toolbarControl != null)
                    {
                        KCT_GameStates.toolbarControl.SetTrue();
                    }

                    else
                    {
                        showBuildList = true;
                    }
                }
                if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                {
                    InputLockManager.RemoveControlLock("KCTKSCLock");
                }

                for (int j = 0; j < KCT_GameStates.TechList.Count; j++)
                {
                    KCT_GameStates.TechList[j].UpdateBuildRate(j);
                }

                foreach (KCT_KSC ksc in KCT_GameStates.KSCs)
                {
                    ksc.RecalculateBuildRates();
                    ksc.RecalculateUpgradedBuildRates();
                }
                KCT_GUI.ResetFormulaRateHolders();
            }
            if (GUILayout.Button("Cancel", GUILayout.ExpandWidth(false)))
            {
                WorkingPreset = null;
                showSettings  = false;
                if (!PrimarilyDisabled && !showFirstRun)
                {
                    ResetBLWindow();

                    //if (KCT_Events.instance.KCTButtonStock != null)
                    //    KCT_Events.instance.KCTButtonStock.SetTrue();
                    if (KCT_GameStates.toolbarControl != null)
                    {
                        KCT_GameStates.toolbarControl.SetTrue();
                    }

                    else
                    {
                        showBuildList = true;
                    }
                }

                for (int j = 0; j < KCT_GameStates.TechList.Count; j++)
                {
                    KCT_GameStates.TechList[j].UpdateBuildRate(j);
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();                       //end column 2

            GUILayout.BeginVertical(GUILayout.Width(100)); //Start general settings
            GUILayout.Label("General Settings", yellowText);
            GUILayout.Label("NOTE: Affects all saves!", yellowText);
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            GUILayout.Label("Max Timewarp");
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
            {
                newTimewarp = Math.Max(newTimewarp - 1, 0);
            }
            //current warp setting
            GUILayout.Label(TimeWarp.fetch.warpRates[newTimewarp] + "x");
            if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
            {
                newTimewarp = Math.Min(newTimewarp + 1, TimeWarp.fetch.warpRates.Length - 1);
            }
            GUILayout.EndHorizontal();

            forceStopWarp     = GUILayout.Toggle(forceStopWarp, "Auto Stop TimeWarp", HighLogic.Skin.button);
            autoAlarms        = GUILayout.Toggle(autoAlarms, "Auto KAC Alarms", HighLogic.Skin.button);
            overrideLaunchBtn = GUILayout.Toggle(overrideLaunchBtn, "Override Launch Button", HighLogic.Skin.button);
            //useBlizzyToolbar = GUILayout.Toggle(useBlizzyToolbar, "Use Toolbar Mod", HighLogic.Skin.button);
            disableAllMsgs = !GUILayout.Toggle(!disableAllMsgs, "Use Message System", HighLogic.Skin.button);
            debug          = GUILayout.Toggle(debug, "Debug Logging", HighLogic.Skin.button);

#if DEBUG
            debugUpdateChecking = GUILayout.Toggle(debugUpdateChecking, "Check for Dev Updates", HighLogic.Skin.button);
#endif

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

            GUILayout.EndHorizontal(); //end main split
            GUILayout.EndVertical();   //end window

            changed = GUI.changed;

            if (!Input.GetMouseButtonDown(1) && !Input.GetMouseButtonDown(2))
            {
                GUI.DragWindow();
            }
        }
Beispiel #27
0
        public static void DelayedStart()
        {
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }

            KCTDebug.Log("DelayedStart start");
            if (KCT_PresetManager.Instance?.ActivePreset == null || !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                return;
            }

            if (KCT_GUI.PrimarilyDisabled)
            {
                return;
            }

            //The following should only be executed when fully enabled for the save

            if (KCT_GameStates.ActiveKSC == null)
            {
                KCT_Utilities.SetActiveKSCToRSS();
            }

            KCTDebug.Log("Checking vessels for missing parts.");
            //check that all parts are valid in all ships. If not, warn the user and disable that vessel (once that code is written)
            if (!KCT_GameStates.vesselErrorAlerted)
            {
                List <KCT_BuildListVessel> erroredVessels = new List <KCT_BuildListVessel>();
                foreach (KCT_KSC KSC in KCT_GameStates.KSCs) //this is faster on subsequent scene changes
                {
                    foreach (KCT_BuildListVessel blv in KSC.VABList)
                    {
                        if (!blv.allPartsValid)
                        {
                            //error!
                            KCTDebug.Log(blv.shipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                    foreach (KCT_BuildListVessel blv in KSC.VABWarehouse)
                    {
                        if (!blv.allPartsValid)
                        {
                            //error!
                            KCTDebug.Log(blv.shipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                    foreach (KCT_BuildListVessel blv in KSC.SPHList)
                    {
                        if (!blv.allPartsValid)
                        {
                            //error!
                            KCTDebug.Log(blv.shipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                    foreach (KCT_BuildListVessel blv in KSC.SPHWarehouse)
                    {
                        if (!blv.allPartsValid)
                        {
                            //error!
                            KCTDebug.Log(blv.shipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                }
                if (erroredVessels.Count > 0)
                {
                    PopUpVesselError(erroredVessels);
                }
                KCT_GameStates.vesselErrorAlerted = true;
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (KCT_GameStates.EditorShipEditingMode)
                {
                    KCTDebug.Log("Editing " + KCT_GameStates.editedVessel.shipName);
                    EditorLogic.fetch.shipNameField.text = KCT_GameStates.editedVessel.shipName;
                }
            }
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                KCTDebug.Log("SP Start");
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    if (ToolbarManager.ToolbarAvailable && KCT_GameStates.settings.PreferBlizzyToolbar)
                    {
                        if (KCT_GameStates.showWindows[0])
                        {
                            KCT_GUI.ClickOn();
                        }
                        else
                        {
                            //if (KCT_Events.instance != null && KCT_Events.instance.KCTButtonStock != null)
                            if (KCT_Events.instance != null && KCT_GameStates.toolbarControl != null)

                            {
                                if (KCT_GameStates.showWindows[0])
                                {
                                    KCT_GUI.ClickOn();
                                }
                            }
                        }
                    }
                    KCT_GUI.ResetBLWindow();
                }
                else
                {
                    KCT_GUI.showBuildList         = false;
                    KCT_GameStates.showWindows[0] = false;
                }
                KCTDebug.Log("SP UI done");

                if (KCT_GameStates.firstStart)
                {
                    KCTDebug.Log("Showing first start.");
                    KCT_GameStates.firstStart = false;
                    KCT_GUI.showFirstRun      = true;

                    //initialize the proper launchpad
                    KCT_GameStates.ActiveKSC.ActiveLPInstance.level = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.LaunchPad);
                }

                KCTDebug.Log("SP switch starting");
                KCT_GameStates.ActiveKSC.SwitchLaunchPad(KCT_GameStates.ActiveKSC.ActiveLaunchPadID);
                KCTDebug.Log("SP switch done");

                foreach (KCT_KSC ksc in KCT_GameStates.KSCs)
                {
                    for (int i = 0; i < ksc.Recon_Rollout.Count; i++)
                    {
                        KCT_Recon_Rollout rr = ksc.Recon_Rollout[i];
                        if (rr.RRType != KCT_Recon_Rollout.RolloutReconType.Reconditioning && KCT_Utilities.FindBLVesselByID(new Guid(rr.associatedID)) == null)
                        {
                            KCTDebug.Log("Invalid Recon_Rollout at " + ksc.KSCName + ". ID " + rr.associatedID + " not found.");
                            ksc.Recon_Rollout.Remove(rr);
                            i--;
                        }
                    }

                    for (int i = 0; i < ksc.AirlaunchPrep.Count; i++)
                    {
                        KCT_AirlaunchPrep ap = ksc.AirlaunchPrep[i];
                        if (KCT_Utilities.FindBLVesselByID(new Guid(ap.associatedID)) == null)
                        {
                            KCTDebug.Log("Invalid KCT_AirlaunchPrep at " + ksc.KSCName + ". ID " + ap.associatedID + " not found.");
                            ksc.AirlaunchPrep.Remove(ap);
                            i--;
                        }
                    }
                }
                KCTDebug.Log("SP done");
            }
            KCTDebug.Log("DelayedStart finished");
        }
Beispiel #28
0
        public void Start()
        {
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }

            KCTDebug.Log("Start called");

            // Subscribe to events from KSP and other mods
            if (!KCT_Events.instance.subscribedToEvents)
            {
                KCT_Events.instance.SubscribeToEvents();
            }

            KCT_GameStates.settings.Save(); //Save the settings file, with defaults if it doesn't exist
            KCT_PresetManager.Instance.SaveActiveToSaveData();

            // Ghetto event queue
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                InvokeRepeating("EditorRecalculation", 1, 1);

                KCT_GUI.buildRateForDisplay = null;
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);
                }
            }

            if (KCT_GUI.PrimarilyDisabled)
            {
                if (InputLockManager.GetControlLock("KCTLaunchLock") == ControlTypes.EDITOR_LAUNCH)
                {
                    InputLockManager.RemoveControlLock("KCTLaunchLock");
                }
            }

            KACWrapper.InitKACWrapper();

            if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                if (InputLockManager.GetControlLock("KCTKSCLock") == ControlTypes.KSC_FACILITIES)
                {
                    InputLockManager.RemoveControlLock("KCTKSCLock");
                }
                return;
            }

            //Begin primary mod functions

            KCT_GameStates.UT = Planetarium.GetUniversalTime();

            KCT_GUI.guiDataSaver.Load();

            switch (HighLogic.LoadedScene)
            {
            case GameScenes.EDITOR:

                //if (HighLogic.LoadedSceneIsEditor)
            {
                KCT_GUI.hideAll();
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_GUI.showEditorGUI = KCT_GameStates.showWindows[1];
                    if (KCT_GUI.showEditorGUI)
                    {
                        KCT_GUI.ClickOn();
                    }
                    else
                    {
                        KCT_GUI.ClickOff();
                    }
                }
            }
            break;

            case GameScenes.SPACECENTER:
                //else if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                bool shouldStart = KCT_GUI.showFirstRun;
                KCT_GUI.hideAll();
                if (!shouldStart)
                {
                    KCT_GUI.showBuildList = KCT_GameStates.showWindows[0];
                    if (KCT_GUI.showBuildList)
                    {
                        KCT_GUI.ClickOn();
                    }
                    else
                    {
                        KCT_GUI.ClickOff();
                    }
                }
                KCT_GUI.showFirstRun = shouldStart;
            }
            break;

            case GameScenes.FLIGHT:
                if (/*HighLogic.LoadedSceneIsFlight && */ FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH &&
                    FlightGlobals.ActiveVessel.GetCrewCount() == 0 && KCT_GameStates.launchedCrew.Count > 0)
                {
                    KerbalRoster roster = HighLogic.CurrentGame.CrewRoster;

                    for (int i = 0; i < FlightGlobals.ActiveVessel.parts.Count; i++)
                    {
                        Part p = FlightGlobals.ActiveVessel.parts[i];
                        //KCTDebug.Log("craft: " + p.craftID);
                        KCTDebug.LogError("Part being tested: " + p.partInfo.title);
                        {
                            CrewedPart cP = KCT_GameStates.launchedCrew.Find(part => part.partID == p.craftID);
                            if (cP == null)
                            {
                                continue;
                            }
                            List <ProtoCrewMember> crewList = cP.crewList;
                            KCTDebug.LogError("cP.crewList.Count: " + cP.crewList.Count);
                            foreach (ProtoCrewMember crewMember in crewList)
                            {
                                if (crewMember != null)
                                {
                                    ProtoCrewMember finalCrewMember = crewMember;
                                    if (crewMember.type == ProtoCrewMember.KerbalType.Crew)
                                    {
                                        finalCrewMember = roster.Crew.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    else if (crewMember.type == ProtoCrewMember.KerbalType.Tourist)
                                    {
                                        finalCrewMember = roster.Tourist.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    if (finalCrewMember == null)
                                    {
                                        KCTDebug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name + ". Cannot find Kerbal in list.");
                                        continue;
                                    }
                                    try
                                    {
                                        KCTDebug.Log("Assigning " + finalCrewMember.name + " to " + p.partInfo.name);
                                        if (p.AddCrewmember(finalCrewMember))    //p.AddCrewmemberAt(finalCrewMember, crewList.IndexOf(crewMember)))
                                        {
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                                            if (finalCrewMember.seat != null)
                                            {
                                                finalCrewMember.seat.SpawnCrew();
                                            }
                                        }
                                        else
                                        {
                                            KCTDebug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                            continue;
                                        }
                                    }
                                    catch
                                    {
                                        KCTDebug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                        finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                    KCT_GameStates.launchedCrew.Clear();
                }
                //if (HighLogic.LoadedSceneIsFlight)
                {
                    KCT_GUI.hideAll();
                    if (KCT_GameStates.launchedVessel != null && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH)
                    {
                        KCT_GameStates.launchedVessel.KSC = null;     //it's invalid now
                        KCTDebug.Log("Attempting to remove launched vessel from build list");
                        bool removed = KCT_GameStates.launchedVessel.RemoveFromBuildList();
                        if (removed)     //Only do these when the vessel is first removed from the list
                        {
                            //Add the cost of the ship to the funds so it can be removed again by KSP
                            KCT_Utilities.AddFunds(KCT_GameStates.launchedVessel.cost, TransactionReasons.VesselRollout);
                            FlightGlobals.ActiveVessel.vesselName = KCT_GameStates.launchedVessel.shipName;
                        }

                        KCT_Recon_Rollout rollout = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == KCT_GameStates.launchedVessel.id.ToString());
                        if (rollout != null)
                        {
                            KCT_GameStates.ActiveKSC.Recon_Rollout.Remove(rollout);
                        }

                        KCT_AirlaunchPrep alPrep = KCT_GameStates.ActiveKSC.AirlaunchPrep.FirstOrDefault(r => r.associatedID == KCT_GameStates.launchedVessel.id.ToString());
                        if (alPrep != null)
                        {
                            KCT_GameStates.ActiveKSC.AirlaunchPrep.Remove(alPrep);
                        }

                        AirlaunchParams alParams = KCT_GameStates.AirlaunchParams;
                        if (alParams != null && alParams.KCTVesselId == KCT_GameStates.launchedVessel.id &&
                            (!alParams.KSPVesselId.HasValue || alParams.KSPVesselId == FlightGlobals.ActiveVessel.id))
                        {
                            if (!alParams.KSPVesselId.HasValue)
                            {
                                alParams.KSPVesselId = FlightGlobals.ActiveVessel.id;
                            }
                            StartCoroutine(AirlaunchRoutine(alParams, FlightGlobals.ActiveVessel.id));
                        }
                    }
                }
                break;
            }

            ratesUpdated = false;
            KCTDebug.Log("Start finished");

            wfsOne  = new WaitForSeconds(1f);
            wfsTwo  = new WaitForSeconds(2f);
            wfsHalf = new WaitForSeconds(0.5f);

            DelayedStart();

            UpdateTechlistIconColor();
            StartCoroutine(HandleEditorButton_Coroutine());
        }
Beispiel #29
0
 public void HideAllGUIs()
 {
     //KCT_GUI.hideAll();
     KCT_GUI.ClickOff();
 }
Beispiel #30
0
        public void DelayedStart()
        {
            if (Utilities.CurrentGameIsMission())
            {
                return;
            }

            KCTDebug.Log("DelayedStart start");
            if (PresetManager.Instance?.ActivePreset == null || !PresetManager.Instance.ActivePreset.GeneralSettings.Enabled)
            {
                return;
            }

            if (KCT_GUI.IsPrimarilyDisabled)
            {
                return;
            }

            //The following should only be executed when fully enabled for the save

            if (KCTGameStates.ActiveKSC == null)
            {
                Utilities.SetActiveKSCToRSS();
            }

            KCTDebug.Log("Checking vessels for missing parts.");
            //check that all parts are valid in all ships. If not, warn the user and disable that vessel (once that code is written)
            if (!KCTGameStates.VesselErrorAlerted)
            {
                var erroredVessels = new List <BuildListVessel>();
                foreach (KSCItem KSC in KCTGameStates.KSCs) //this is faster on subsequent scene changes
                {
                    foreach (BuildListVessel blv in KSC.VABList)
                    {
                        if (!blv.AllPartsValid)
                        {
                            KCTDebug.Log(blv.ShipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                    foreach (BuildListVessel blv in KSC.VABWarehouse)
                    {
                        if (!blv.AllPartsValid)
                        {
                            KCTDebug.Log(blv.ShipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                    foreach (BuildListVessel blv in KSC.SPHList)
                    {
                        if (!blv.AllPartsValid)
                        {
                            KCTDebug.Log(blv.ShipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                    foreach (BuildListVessel blv in KSC.SPHWarehouse)
                    {
                        if (!blv.AllPartsValid)
                        {
                            KCTDebug.Log(blv.ShipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                }
                if (erroredVessels.Count > 0)
                {
                    PopUpVesselError(erroredVessels);
                }
                KCTGameStates.VesselErrorAlerted = true;
            }

            if (HighLogic.LoadedSceneIsEditor && KCTGameStates.EditorShipEditingMode)
            {
                KCTDebug.Log($"Editing {KCTGameStates.EditedVessel.ShipName}");
                EditorLogic.fetch.shipNameField.text = KCTGameStates.EditedVessel.ShipName;
            }

            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                KCTDebug.Log("SP Start");
                if (!KCT_GUI.IsPrimarilyDisabled)
                {
                    if (ToolbarManager.ToolbarAvailable && KCTGameStates.Settings.PreferBlizzyToolbar)
                    {
                        if (KCTGameStates.ShowWindows[0])
                        {
                            KCT_GUI.ToggleVisibility(true);
                        }
                        else
                        {
                            if (KCTEvents.Instance != null && KCTGameStates.ToolbarControl != null)
                            {
                                if (KCTGameStates.ShowWindows[0])
                                {
                                    KCT_GUI.ToggleVisibility(true);
                                }
                            }
                        }
                    }
                    KCT_GUI.ResetBLWindow();
                }
                else
                {
                    KCT_GUI.GUIStates.ShowBuildList = false;
                    KCTGameStates.ShowWindows[0]    = false;
                }
                KCTDebug.Log("SP UI done");

                if (KCTGameStates.IsFirstStart)
                {
                    KCTDebug.Log("Showing first start.");
                    KCTGameStates.IsFirstStart     = false;
                    KCT_GUI.GUIStates.ShowFirstRun = true;

                    //initialize the proper launchpad
                    KCTGameStates.ActiveKSC.ActiveLPInstance.level = Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.LaunchPad);
                }

                KCTDebug.Log("SP switch starting");
                KCTGameStates.ActiveKSC.SwitchLaunchPad(KCTGameStates.ActiveKSC.ActiveLaunchPadID);
                KCTDebug.Log("SP switch done");

                foreach (KSCItem ksc in KCTGameStates.KSCs)
                {
                    for (int i = 0; i < ksc.Recon_Rollout.Count; i++)
                    {
                        ReconRollout rr = ksc.Recon_Rollout[i];
                        if (rr.RRType != ReconRollout.RolloutReconType.Reconditioning && Utilities.FindBLVesselByID(new Guid(rr.AssociatedID)) == null)
                        {
                            KCTDebug.Log($"Invalid Recon_Rollout at {ksc.KSCName}. ID {rr.AssociatedID} not found.");
                            ksc.Recon_Rollout.Remove(rr);
                            i--;
                        }
                    }

                    for (int i = 0; i < ksc.AirlaunchPrep.Count; i++)
                    {
                        AirlaunchPrep ap = ksc.AirlaunchPrep[i];
                        if (Utilities.FindBLVesselByID(new Guid(ap.AssociatedID)) == null)
                        {
                            KCTDebug.Log($"Invalid KCT_AirlaunchPrep at {ksc.KSCName}. ID {ap.AssociatedID} not found.");
                            ksc.AirlaunchPrep.Remove(ap);
                            i--;
                        }
                    }
                }
                KCTDebug.Log("SP done");
            }

            if (HighLogic.LoadedSceneIsFlight && KCTGameStates.IsSimulatedFlight)
            {
                Utilities.EnableSimulationLocks();
                if (KCTGameStates.SimulationParams.SimulationUT > 0 &&
                    FlightDriver.CanRevertToPrelaunch)    // Used for checking whether the player has saved and then loaded back into that save
                {
                    KCTDebug.Log($"Setting simulation UT to {KCTGameStates.SimulationParams.SimulationUT}");
                    Planetarium.SetUniversalTime(KCTGameStates.SimulationParams.SimulationUT);
                }

                AddSimulationWatermark();
            }

            if (KCTGameStates.IsSimulatedFlight && HighLogic.LoadedSceneIsGame && !HighLogic.LoadedSceneIsFlight)
            {
                string msg = "Current save appears to be a simulation with no way to automatically revert to the pre-simulation state. An older save needs to be loaded manually now.";
                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "errorPopup", "KCT Simulation error", msg, "Understood", false, HighLogic.UISkin);
            }

            KCTDebug.Log("DelayedStart finished");
        }