Пример #1
0
        // add filters for a set of tag-based situations
        public static void FilterResearchArchive(string[] situations)
        {
            // note: cache the controller, because FindObjectOfType is slow as hell
            RDArchivesController ctrl = (UnityEngine.Object.FindObjectOfType(typeof(RDArchivesController)) as RDArchivesController);

            if (ctrl != null && ctrl.dropdownListContainer != null && ctrl.dropdownListContainer.lists != null && ctrl.dropdownListContainer.lists.Length >= 3)
            {
                foreach (string situation in situations)
                {
                    // try to get the item
                    KSP.UI.UIListItem item;
                    items.TryGetValue(situation, out item);

                    // if there is no item, or the list was reset
                    if (items == null || !ctrl.dropdownListContainer.lists[1].scrollList.Contains(item))
                    {
                        // get number of matching reports
                        int count = ResearchAndDevelopment.GetSubjects().FindAll(k => k.id.Contains(situation)).Count;

                        // if there is no report, do nothing
                        if (count == 0)
                        {
                            return;
                        }

                        // create and add it
                        item = ctrl.dropdownListContainer.lists[1].AddItem(situation, situation.AddSpacesOnCaps(), count == 1 ? "1 report" : count + " reports");
                        items.Remove(situation);
                        items.Add(situation, item);
                    }
                }
            }
        }
Пример #2
0
        // Awake() is the first function called in the lifecycle of a Unity3D MonoBehaviour.  In the case of KSP,
        // it happens to be called right before the game's PSystem is instantiated from PSystemManager.Instance.systemPrefab
        public void Awake()
        {
            // Abort, if KSP isn't compatible
            if (!CompatibilityChecker.IsCompatible())
            {
                string supported = CompatibilityChecker.version_major + "." + CompatibilityChecker.version_minor + "." + CompatibilityChecker.Revision;
                string current   = Versioning.version_major + "." + Versioning.version_minor + "." + Versioning.Revision;
                Debug.LogWarning("[Kopernicus] Detected incompatible install.\nCurrent version of KSP: " + current + ".\nSupported version of KSP: " + supported + ".\nPlease wait, until Kopernicus gets updated to match your version of KSP.");
                Debug.Log("[Kopernicus] Aborting...");

                // Abort
                Destroy(this);
                return;
            }

            // We're ALIVE
            Logger.Default.SetAsActive();
            Logger.Default.Log("Injector.Awake(): Begin");

            // Yo garbage collector - we have work to do man
            DontDestroyOnLoad(this);

            // If the planetary manager does not work, well, error out
            if (PSystemManager.Instance == null)
            {
                // Log the error
                Logger.Default.Log("Injector.Awake(): If PSystemManager.Instance is null, there is nothing to do");
                return;
            }

            // Backup the old prefab
            StockSystemPrefab = PSystemManager.Instance.systemPrefab;

            // Get the current time
            DateTime start = DateTime.Now;

            // Get the configNode
            ConfigNode kopernicus = GameDatabase.Instance.GetConfigs(rootNodeName)[0].config;

            // THIS IS WHERE THE MAGIC HAPPENS - OVERWRITE THE SYSTEM PREFAB SO KSP ACCEPTS OUR CUSTOM SOLAR SYSTEM AS IF IT WERE FROM SQUAD
            PSystemManager.Instance.systemPrefab = Parser.CreateObjectFromConfigNode <Loader>(kopernicus).systemPrefab;

            // SEARCH FOR THE ARCHIVES CONTROLLER PREFAB AND OVERWRITE IT WITH THE CUSTOM SYSTEM
            RDArchivesController archivesController = AssetBase.RnDTechTree.GetRDScreenPrefab().GetComponentsInChildren <RDArchivesController> (true).First();

            archivesController.systemPrefab = PSystemManager.Instance.systemPrefab;

            // Clear space center instance so it will accept nouveau Kerbin
            SpaceCenter.Instance = null;

            // Add a handler so that we can do post spawn fixups.
            PSystemManager.Instance.OnPSystemReady.Add(PostSpawnFixups);

            // Done executing the awake function
            TimeSpan duration = (DateTime.Now - start);

            Logger.Default.Log("Injector.Awake(): Completed in: " + duration.TotalMilliseconds + " ms");
            Logger.Default.Flush();
        }
Пример #3
0
        void Update()
        {
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER && SigmaBinary.archivesFixerList?.Count > 0)
            {
                RDArchivesController[] items = Resources.FindObjectsOfTypeAll <RDArchivesController>();

                for (int i = 0; i < items?.Length; i++)
                {
                    RDArchivesController item = items[i];
                    item.gameObject.AddOrGetComponent <ArchivesFixer>();
                }
            }
        }
Пример #4
0
        public static void AddPlanets()
        {
            RDPlanetListItemContainer[] planetItems = Resources.FindObjectsOfTypeAll <RDPlanetListItemContainer>().Where(i => i.label_planetName.text != "Planet name").ToArray();
            for (Int32 i = 0; i < planetItems.Length; i++)
            {
                DestroyImmediate(planetItems[i]);
            }

            // Stuff needed for AddPlanets
            FieldInfo            list = typeof(RDArchivesController).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).Skip(7).FirstOrDefault();
            MethodInfo           add  = typeof(RDArchivesController).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)?.Skip(26)?.FirstOrDefault();
            RDArchivesController RDAC = Resources.FindObjectsOfTypeAll <RDArchivesController>().FirstOrDefault();

            // AddPlanets requires this list to be empty when triggered
            list.SetValue(RDAC, new Dictionary <String, List <RDArchivesController.Filter> >());

            // AddPlanets!
            add.Invoke(RDAC, null);
        }
Пример #5
0
        /**
         * Awake() is the first function called in the lifecycle of a Unity3D MonoBehaviour.  In the case of KSP,
         * it happens to be called right before the game's PSystem is instantiated from PSystemManager.Instance.systemPrefab
         *
         * TL,DR - Custom planet injection happens here
         *
         **/
        public void Awake()
        {
            // We're ALIVE
            Logger.Default.SetAsActive();
            Logger.Default.Log("Injector.Awake(): Begin");

            // Yo garbage collector - we have work to do man
            DontDestroyOnLoad(this);

            // If the planetary manager does not work, well, error out
            if (PSystemManager.Instance == null)
            {
                // Log the error
                Logger.Default.Log("Injector.Awake(): If PSystemManager.Instance is null, there is nothing to do");
                return;
            }

            // Get the current time
            DateTime start = DateTime.Now;

            // THIS IS WHERE THE MAGIC HAPPENS - OVERWRITE THE SYSTEM PREFAB SO KSP ACCEPTS OUR CUSTOM SOLAR SYSTEM AS IF IT WERE FROM SQUAD
            PSystemManager.Instance.systemPrefab = (new Configuration.Loader()).Generate();

            // SEARCH FOR THE ARCHIVES CONTROLLER PREFAB AND OVERWRITE IT WITH THE CUSTOM SYSTEM
            RDArchivesController archivesController = AssetBase.RnDTechTree.GetRDScreenPrefab().GetComponentsInChildren <RDArchivesController> (true).First();

            archivesController.systemPrefab = PSystemManager.Instance.systemPrefab;

            // Clear space center instance so it will accept nouveau Kerbin
            SpaceCenter.Instance = null;

            // Add a handler so that we can do post spawn fixups.
            PSystemManager.Instance.OnPSystemReady.Add(PostSpawnFixups);

            // Done executing the awake function
            TimeSpan duration = (DateTime.Now - start);

            Logger.Default.Log("Injector.Awake(): Completed in: " + duration.TotalMilliseconds + " ms");
            Logger.Default.Flush();
        }
Пример #6
0
        private IEnumerator Searching()
        {
            WaitForSeconds wait = new WaitForSeconds(0.1f);

            RDArchivesController RDController = null;

            while (RDController == null)
            {
                var resControllers = Resources.FindObjectsOfTypeAll <RDArchivesController>();

                if (resControllers != null)
                {
                    for (int i = resControllers.Length - 1; i >= 0; i--)
                    {
                        RDArchivesController rd = resControllers[i];

                        if (rd == null)
                        {
                            continue;
                        }

                        RDController = rd;
                        break;
                    }
                }

                if (RDController == null)
                {
                    yield return(wait);
                }
            }

            if (RDController != null)
            {
                _RDPlanetPrefab = RDController.planetListItemPrefab;
            }
        }