示例#1
0
        static public bool SaveKeoCacheFile(KeoCacheCollection keoCache)
        {
            ConfigNode collectionData = KeoCacheCollection.SaveCollectionToConfigNode(keoCache);
            ConfigNode fileNode       = new ConfigNode();

            fileNode.AddNode(FileIO.KEOCACHE_COLLECTION, collectionData);


            Log.Info("Creating directory: " + GetCacheDir);
            Directory.CreateDirectory(GetCacheDir);
            try
            {
                Log.Info("Saving to file: " + CollectionFileName(keoCache.keocacheCollectionData.collectionId));
                fileNode.Save(CollectionFileName(keoCache.keocacheCollectionData.collectionId));

                KeoCacheDriver.Instance.ReadAllCaches();

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error("Error saving KeoCache Collection: " + ex.Message);
            }
            return(false);
        }
示例#2
0
        static public KeoCacheCollection LoadKeoCacheData(string fname)
        {
            KeoCacheCollection keoCache = null;

            Log.Info("LoadKeoCacheData, file:" + fname);
            if (File.Exists(fname))
            {
                Log.Info("File exists");

                ConfigNode file = ConfigNode.Load(fname);
                if (file != null)
                {
                    ConfigNode loadedCollectionNode = file.GetNode(KEOCACHE_COLLECTION);

                    if (loadedCollectionNode != null)
                    {
                        keoCache = KeoCacheCollection.LoadCollectionFromConfigNode(loadedCollectionNode);
                    }
                    else
                    {
                        Log.Info("loadedCollectionNode is null");
                    }
                }
                else
                {
                    Log.Info("Error loading file: " + fname);
                }
            }
            return(keoCache);
        }
        void KeoCaching_Collection_Window(int windowId)
        {
            saveable = true;
            if (loadDialog)
            {
                loadDialog = false;
                // following to avoid some nullrefs
                Log.Info("Setting activeKeoCacheCollection to null 2");
                activeKeoCacheCollection = new KeoCacheCollection();
                StartLoadDialog(ParentWin.collection, collectionWinRect);
            }
            GUILayout.BeginHorizontal();


            GUILayout.BeginVertical();
            DisplayCollectionData();
            // GUILayout.FlexibleSpace();
            GUILayout.EndVertical();

            if (!visibleActiveCollectionsReadOnly)
            {
                GUILayout.BeginVertical();
                DisplayCollectionCaches();
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            DisplayCollectionButtons();
            GUILayout.EndHorizontal();
            GUI.DragWindow();
        }
示例#4
0
        public void SetCollection(string g, KeoCacheCollection kcc = null)
        {
            Log.Info("SetCollection, g: " + g);
            if (g != null && g != "")
            {
                Events["SelectTravelbug"].guiActiveEditor = false;
                //Events["SelectTravelbug"].guiActive = false;

                //if (HighLogic.LoadedSceneIsEditor)
                Events["ClearTravelbug"].guiActiveEditor = true;
                //KeoScenario.activeKeoCacheCollections.Add(g, kcc);

                this.tbKcc = kcc;
                if (tbKcc == null)
                {
                    Log.Info("SetColleciton, tbKcc is null");
                }
            }
            else
            {
                Events["SelectTravelbug"].guiActiveEditor = true;
                Events["ClearTravelbug"].guiActiveEditor  = false;
                //KeoScenario.activeKeoCacheCollections[collectionID].keocacheCollectionData.assignedTravelBug = "";
                this.tbKcc = null;
            }
            collectionID = g;
            //if (HighLogic.LoadedSceneIsEditor)
            collectionIDInEditor = g;
            //else
            //    collectionID = g;
        }
示例#5
0
        void FlightWindow()
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("New KeoCache Collection"))
            {
                activeKeoCacheCollection = new KeoCacheCollection();
                visibleEditCollection    = true;
                visibleMenu    = false;
                editInProgress = true;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Select KeoCache for editing"))
            {
                //visibleEditCollection = true;
                visibleMenu           = false;
                visibleAllCollections = true;
                // need to get the active collections window to only display collections not active, and a way to select one
                selectForEdit = true;
            }
            GUILayout.EndHorizontal();

            if (activeKeoCacheCollection != null)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Edit: " + activeKeoCacheCollection.keocacheCollectionData.name))
                {
                    visibleEditCollection = true;
                    visibleMenu           = false;
                }
                GUILayout.EndHorizontal();
            }
        }
示例#6
0
        void SaveScenarios(ConfigNode node)
        {
            base.OnSave(node);
#if false
            ConfigNode collectionNode = new ConfigNode();
            foreach (var cache in KeoScenario.activeKeoCacheCollections)
            {
                Log.Info("SaveScenarios, name: " + cache.Value.keocacheCollectionData.name);
                Log.Info("assignedTravelBug: " + cache.Value.keocacheCollectionData.assignedTravelBug);
                if (cache.Value.keocacheCollectionData.assignedTravelBug != "")
                {
                    ConfigNode configNode = KeoCacheCollection.SaveCollectionToConfigNode(cache.Value);
                    if (configNode != null)
                    {
                        Log.Info("configNode not null");
                        string nodeName = cache.Value.keocacheCollectionData.collectionId.ToString();
                        if (collectionNode.HasNode(nodeName))
                        {
                            Log.Info("SetNode");
                            collectionNode.SetNode(nodeName, configNode);
                        }
                        else
                        {
                            Log.Info("AddNode");
                            collectionNode.AddNode(nodeName, configNode);
                        }
                    }
                }
            }
            node.AddNode(SCENARIO, collectionNode);
#endif
        }
        IEnumerator ReadAllCachesCoroutine()
        {
            yield return(null);

            Log.Info("CacheDir: " + FileIO.GetCacheDir + ",   suffix: " + FileIO.SUFFIX);
            string[] files = Directory.GetFiles(FileIO.GetCacheDir, "*" + FileIO.SUFFIX);
            foreach (var f in files)
            {
                Log.Info("File: " + f);
                KeoCacheCollection s = FileIO.LoadKeoCacheData(f);
                if (s != null && s.keocacheCollectionData != null)
                {
                    AvailableCache ac = new AvailableCache();

                    ac.path      = f;
                    ac.id        = s.keocacheCollectionData.collectionId;
                    ac.name      = s.keocacheCollectionData.name;
                    ac.numCaches = s.keoCacheDataList.Count;
                    Log.Info("ReadAllCachesCoroutine, id: " + ac.id + ", name: " + ac.name);
                    availableCaches.Add(ac.name, ac);
                }
                else
                {
                    if (s == null)
                    {
                        Log.Info("s is null");
                    }
                    if (s.keocacheCollectionData == null)
                    {
                        Log.Info("s.keocacheCollectionData is null");
                    }
                }

#if false
                KeoCacheCollection s = FileIO.LoadKeoCacheData(f);
                if (s != null && s.keocacheCollectionData != null)
                {
                    KeoCacheCollection data;
                    if (KeoScenario.activeKeoCacheCollections.TryGetValue(s.keocacheCollectionData.collectionId, out data))
                    {
                        if (data.keocacheCollectionData.assignedTravelBug != "")
                        {
                            continue;
                        }
                        KeoScenario.activeKeoCacheCollections.Remove(s.keocacheCollectionData.collectionId);
                    }
                    KeoScenario.activeKeoCacheCollections.Add(s.keocacheCollectionData.collectionId, s);
                }
#endif
                //yield return null;
                yield return(null);
            }
        }
示例#8
0
        public override void OnLoad(ConfigNode node)
        {
            Log.Info("KeoTravelBugModule.OnLoad");
            if (this.vessel != null)
            {
                Log.Info("vessel: " + this.vessel.vesselName);
            }
            ConfigNode loadedCollectionNode = node.GetNode(FileIO.KEOCACHE_COLLECTION);

            if (loadedCollectionNode != null)
            {
                Log.Info("OnLoad Loading KeoCacheCollection");
                tbKcc = KeoCacheCollection.LoadCollectionFromConfigNode(loadedCollectionNode);
            }
            base.OnLoad(node);
        }
示例#9
0
        static public bool AddCollection(KeoCacheCollection cache)
        {
#if false
            if (KeoScenario.activeKeoCacheCollections.ContainsKey(cache.keocacheCollectionData.collectionId))
            {
                Log.Info("collectionId exists in active collection");
                foreach (var k in activeKeoCacheCollections)
                {
                    Log.Info("Key: " + k.Key);
                }
                return(false);
            }
            Log.Info("KeoScenario.AddCollection, adding collectionId: " + cache.keocacheCollectionData.collectionId);
            KeoScenario.activeKeoCacheCollections.Add(cache.keocacheCollectionData.collectionId, cache);
#endif
            return(true);
        }
        void UpdateRetrievedCaches(bool testing = false)
        {
            int switch_ = new System.Random().Next() % 3;

            retrievedCaches.Clear();
            if (switch_ == 0)
            {
                KeoCacheCollection     coll = new KeoCacheCollection();
                KeoCacheCollectionData cd   = new KeoCacheCollectionData();
                cd.name        = "Hard boi 1";
                cd.title       = "Hello There";
                cd.author      = "Benjamin Kerman";
                cd.description = "This is a tester boi";
                cd.difficulty  = Difficulty.Insane;
                coll.keocacheCollectionData = cd; retrievedCaches.Add(new Tuple <KeoCacheCollection, bool>(coll, false));
            }
            else if (switch_ == 1)
            {
                KeoCacheCollection     coll = new KeoCacheCollection();
                KeoCacheCollectionData cd   = new KeoCacheCollectionData();
                cd.name        = "Hard boi 2";
                cd.title       = "What the...";
                cd.author      = "Linuxboi";
                cd.description = "woweee this is cool";
                cd.difficulty  = Difficulty.Normal;
                coll.keocacheCollectionData = cd;
                retrievedCaches.Add(new Tuple <KeoCacheCollection, bool>(coll, false));
            }
            else
            {
                KeoCacheCollection     coll = new KeoCacheCollection();
                KeoCacheCollectionData cd   = new KeoCacheCollectionData();
                cd.name        = "Easy man";
                cd.title       = "dun dun DUN!";
                cd.author      = "Kataochi";
                cd.description = "boi oh boy oh boph";
                cd.difficulty  = Difficulty.Easy;
                coll.keocacheCollectionData = cd;
                retrievedCaches.Add(new Tuple <KeoCacheCollection, bool>(coll, false));
            }
        }
示例#11
0
        void SelectKeoCacheForBug(string path)
        {
            KeoCacheCollection s1 = FileIO.LoadKeoCacheData(path);

            if (s1 != null)
            {
                KeoCacheDriver.activeKeoCacheCollection = s1;
                activeBug.SetCollection(s1.keocacheCollectionData.collectionId, s1);

                //Log.Info("ActiveCollectionsWindow, collectionId: " + s1.keocacheCollectionData.collectionId + ",  g.Key: " + g.Key);
                //g.Value.keocacheCollectionData.assignedTravelBug = activeBug.travelbugId;

                selectCollection = selectForEdit = false;
                KeoCacheDriver.Instance.visibleAllCollections = false;
            }
            else
            {
                ScreenMessages.PostScreenMessage("KeoCache collection not available anymore", 10f, ScreenMessageStyle.UPPER_CENTER);
                ReadAllCaches();
            }
        }
示例#12
0
        public override void OnSave(ConfigNode node)
        {
            base.OnSave(node);
            Log.Info("KeoTravelBugModule.OnSave");
            if (this.vessel != null)
            {
                Log.Info("vessel: " + this.vessel.vesselName);
            }
            if (tbKcc != null)
            {
                Log.Info("OnSave Saving KeoCacheCollection, keocacheCollectionData.name: " + tbKcc.keocacheCollectionData.name);
                ConfigNode n = KeoCacheCollection.SaveCollectionToConfigNode(tbKcc);
                Log.Info("OnSave 2");
                var t = KeoCacheCollection.LoadCollectionFromConfigNode(n);

                node.RemoveNodes(FileIO.KEOCACHE_COLLECTION); // probably not necessory
                node.AddNode(FileIO.KEOCACHE_COLLECTION, n);
            }
            else
            {
                Log.Info("In OnSave, tbKss is null");
            }
        }
示例#13
0
        void OnGUI()
        {
            InitializeGUIVars();

            if (hideUI || hideUIwhenPaused)
            {
                return;
            }

            if (HighLogic.CurrentGame.Parameters.CustomParams <KeoCacheOptions>().useKSPskin)
            {
                GUI.skin = HighLogic.Skin;
            }

            if (fsDialog != null && fsDialog.done &&
                fsDialog.SelectedDirectory != null && fsDialog.SelectedFile != null && dialogEntry == null)
            {
                if (fsDialog.SelectedDirectory != "" || fsDialog.SelectedFile != "")
                {
                    KeoScenario.Instance.lastDirectory = fsDialog.SelectedDirectory;
                    localFilePath = fsDialog.SelectedDirectory + FileIO.DirSeperator + fsDialog.SelectedFile;
                    localFilePath = localFilePath.Replace(@"\", "/");
                    if (visibleEditCollection)
                    {
                        var cache = FileIO.LoadKeoCacheData(fsDialog.SelectedDirectory + FileIO.DirSeperator + fsDialog.SelectedFile);
                        if (!visibleAllCollections)
                        {
                            activeKeoCacheCollection = cache;
                        }
                        else
                        {
                            if (!KeoScenario.AddCollection(cache))
                            {
                                // error message here, already in cache
                                ScreenMessages.PostScreenMessage("Collection already loaded", 10f, ScreenMessageStyle.UPPER_CENTER);
                            }
                        }
                    }
                }
                closeFSDialog();
            }
            if (visibleMenu)
            {
                menuWinRect = ClickThruBlocker.GUILayoutWindow(menuWinID, menuWinRect, KeoCaching_Menu_Window, "KeoCaching");
            }
            if (visibleEditCollection && !visibleKeoCache && !visibleAllCollections)
            {
                if (!visibleActiveCollectionsReadOnly)
                {
                    collectionWinRect = ClickThruBlocker.GUILayoutWindow(collectionWinID, collectionWinRect, KeoCaching_Collection_Window, "KeoCache Collection");
                }
                else
                {
                    collectionROWinRect = ClickThruBlocker.GUILayoutWindow(collectionWinID, collectionROWinRect, KeoCaching_Collection_Window, "KeoCache Collection");
                }
            }
            if (visibleKeoCache)
            {
                keocacheWinRect = ClickThruBlocker.GUILayoutWindow(KeocacheWinID, keocacheWinRect, KeoCache_Window, "KeoCache");
            }
            if (visibleHint)
            {
                // Only set the following two IF the hint window hasn't been moved
                // Once it gets moved, then use the saved coordinates
                hintWinRect.x = keocacheWinRect.x + keocacheWinRect.width;
                hintWinRect.y = keocacheWinRect.y;
                hintWinRect   = ClickThruBlocker.GUILayoutWindow(hintWinID, hintWinRect, Hint_Window, "Hint");
            }
            if (visibleTravelBug)
            {
                travelbugWinRect = ClickThruBlocker.GUILayoutWindow(travelbugWinID, travelbugWinRect, TravelBug_Window, "Travel Bugs");
            }
            if (visibleImportWindow)
            {
                importwinRect = ClickThruBlocker.GUILayoutWindow(importWinID, importwinRect, Import_Window, "Import Collection");
            }

            if (visibleAllCollections && !visibleEditCollection)
            {
                string s = "All Collections";
                if (selectForEdit || selectCollection)
                {
                    s = "Available Collections";
                }

                allCollectionsWinRect = ClickThruBlocker.GUILayoutWindow(activeCollectionsID, allCollectionsWinRect, All_Collections_Window, s);
            }
            if (showKerbalX)
            {
                kerbalXWinRect = ClickThruBlocker.GUILayoutWindow(kerbalXWinID, kerbalXWinRect, KerbalXInterface.Instance.IODisplay, "KerbalX Interface");
            }
        }
示例#14
0
        void LoadScenarios(ConfigNode node)
        {
#if false
            Log.Info("LoadScenarios");
            if (node.HasNode(SCENARIO))
            {
                activeKeoCacheCollections = new Dictionary <string, KeoCacheCollection>();

                var gNode = node.GetNode(SCENARIO);
                if (gNode != null)
                {
                    var aNode = gNode.GetNodes();

                    for (int i = 0; i < aNode.Length; i++)
                    {
                        ConfigNode loadedCollectionNode = aNode[i].GetNode(FileIO.KEOCACHE_COLLECTION);
                        var        cache = KeoCacheCollection.LoadCollectionFromConfigNode(loadedCollectionNode);
                        if (cache != null)
                        {
                            Log.Info("LoadScenarios, adding collectionId: " + cache.keocacheCollectionData.collectionId);
                            KeoScenario.activeKeoCacheCollections.Add(cache.keocacheCollectionData.collectionId, cache);
                        }
                    }
                }
#endif
        }

#if false
        void LoadTravelBugs(ConfigNode node)
        {
            if (node.HasNode(SCENARIO))
            {
                travelBugs = new Dictionary <string, TravelBug>();
                var bNode = node.GetNode(TRAVELBUGS);
                if (bNode != null)
                {
                    var bNodes = bNode.GetNodes();
                    for (int i = 0; i < bNodes.Length; i++)
                    {
                        var travelBug = new TravelBug();

                        bNodes[i].TryGetValue("id", ref travelBug.travelbugId);
                        //bNodes[i].TryGetValue("name", ref travelBug.name);
                        bNodes[i].TryGetValue("collectionId", ref travelBug.activeCollectionId);

                        var entries = bNodes[i].GetNodes();
                        for (int e = 0; e < entries.Count() - 1; e++)
                        {
                            TravelBugEntry tbe = new TravelBugEntry();
                            entries[e].TryGetValue("keocachId", ref tbe.keocachId);
                            //entries[e].TryGetValue("hintId", ref tbe.hintId);
                            entries[e].TryGetValue("timeFound", ref tbe.timeFound);

                            travelBug.entries.Add(tbe);
                        }

                        travelBugs.Add(travelBug.travelbugId, travelBug);
                    }
                }
            }
        }
示例#15
0
        void All_Collections_Window(int id)
        {
            //string toDelete = null;
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            scrollPosActiveCollections = GUILayout.BeginScrollView(scrollPosActiveCollections, GUILayout.MinHeight(60), GUILayout.Width(300), GUILayout.MaxHeight(200));
#if true
            FindKeoCaches();
            foreach (var g in availableCaches)
            {
                if (selectCollection)
                {
                    if (g.Value.numCaches < 0)
                    {
                        continue;
                    }
                }
                if (!KeoCacheUsed(g.Value.id))
                {
                    Log.Info("g.value.id: " + g.Value.id);
#if false
                    if (selectForEdit && g.Value.keocacheCollectionData.assignedTravelBug != "")
                    {
                        continue;
                    }
#endif

                    GUILayout.BeginHorizontal();


#if false
                    string s = g.Value.name;
                    if (g.Value.keocacheCollectionData.assignedTravelBug != "")
                    {
                        s += " on vessel ";
                        // need to find vessel from the TravelBugs list
                    }
#endif
                    if (GUILayout.Button(g.Value.name))
                    {
                        if (selectForEdit)
                        {
                            editInProgress = true;
                        }
                        visibleEditCollection            = true;
                        visibleAllCollections            = false;
                        visibleActiveCollectionsReadOnly = !selectForEdit;
                        selectCollection = selectForEdit = false;

                        KeoCacheCollection s1 = FileIO.LoadKeoCacheData(g.Value.path);
                        KeoCacheDriver.activeKeoCacheCollection          = s1;
                        KeoCacheDriver.activeKeoCacheCollection.fullPath = g.Value.path;
                    }

#if false
                    if (g.Value.keocacheCollectionData.assignedTravelBug == null || g.Value.keocacheCollectionData.assignedTravelBug == "")
#endif
                    {
                        if (selectCollection)
                        {
                            if (GUILayout.Button("Select", GUILayout.Width(60)))
                            {
                                SelectKeoCacheForBug(g.Value.path);
                            }
                        }
#if false
                        if (GUILayout.Button("X", redButton, GUILayout.Width(20)))
                        {
                            toDelete = g.Key;
                        }
#endif
                    }
                    GUILayout.EndHorizontal();
                }
            }
#endif
            GUILayout.EndScrollView();
            GUILayout.EndHorizontal();
#if false
            if (toDelete != null)
            {
                Log.Info("toDelete: " + toDelete);
                KeoScenario.activeKeoCacheCollections.Remove(toDelete);
            }
#endif
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Import"))
            {
                //StartLoadDialog();
                ShowImportWindow();
            }

            if (GUILayout.Button("Close"))
            {
                visibleAllCollections = false;
                //editInProgress = false;
                visibleMenu = true;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUI.DragWindow();
        }
        static internal ConfigNode SaveCollectionToConfigNode(KeoCacheCollection keoCache)
        {
            Log.Info("SaveCollectionToConfigNode");
            ConfigNode collectionData = new ConfigNode();

            //ConfigNode fileNode = new ConfigNode();

            collectionData.AddValue("id", keoCache.keocacheCollectionData.collectionId);
            collectionData.AddValue("name", keoCache.keocacheCollectionData.name);
            collectionData.AddValue("title", keoCache.keocacheCollectionData.title);
            collectionData.AddValue("author", keoCache.keocacheCollectionData.author);
            //collectionData.AddValue("description",  keoCache.fileData.description);
            FileIO.AddTextArea("description", keoCache.keocacheCollectionData.description, ref collectionData);
            FileIO.AddTextArea("initialHint", keoCache.keocacheCollectionData.initialHint, ref collectionData);

            collectionData.AddValue("difficulty", keoCache.keocacheCollectionData.difficulty);
            collectionData.AddValue("assignedTravelBug", keoCache.keocacheCollectionData.assignedTravelBug);
            collectionData.AddValue("lastCacheFound", keoCache.keocacheCollectionData.lastCacheFound);
            foreach (var s in keoCache.keocacheCollectionData.requiredMods)
            {
                collectionData.AddValue("requiredMod", s);
            }

            foreach (var keocacheData in keoCache.keoCacheDataList)
            {
                Log.Info("keoCacheName: " + keocacheData.keoCacheName);
                ConfigNode data = new ConfigNode();

                data.AddValue("name", keocacheData.keoCacheName);
                data.AddValue("scienceNodeRequired", keocacheData.scienceNodeRequired);
                data.AddValue("found", keocacheData.found);
                data.AddValue("body", keocacheData.body.name);


                FileIO.AddTextArea("description", keocacheData.description, ref data);

                data.AddValue("lastHintFound", keocacheData.lastHintFound);

                //data.AddValue("nextKeocacheId", keocacheData.nextKeocacheId);
                foreach (var hint in keocacheData.hints)
                {
                    Log.Info("hint.hintTitle: " + hint.hintTitle);
                    ConfigNode h = new ConfigNode();
                    h.AddValue("hintTitle", hint.hintTitle);
                    h.AddValue("distance", hint.hintDistance);
                    h.AddValue("scale", (int)hint.scale);
                    h.AddValue("hint", hint.hint);
                    h.AddValue("situations", (int)hint.situations);
                    //h.AddValue("spawn", hint.spawn);
                    data.AddNode(FileIO.HINT, h);
                }

                data.AddValue("distance", keocacheData.distanceFromCache);
                data.AddValue("scale", (int)keocacheData.scale);

                // Now save the vessel associated with this node
                if (keocacheData.CacheVessel != null)
                {
                    data.AddValue("latitude", keocacheData.CacheVessel.latitude);
                    data.AddValue("longitude", keocacheData.CacheVessel.longitude);
                    ConfigNode vesselNode = new ConfigNode();
                    keocacheData.CacheVessel.BackupVessel().Save(vesselNode);
                    data.AddNode(FileIO.PROTOVESSEL, vesselNode);
                }
                else
                {
                    data.AddValue("latitude", keocacheData.latitude);
                    data.AddValue("longitude", keocacheData.longitude);
                    data.AddNode(FileIO.PROTOVESSEL, keocacheData.protoVessel);
                }
                data.AddValue("spawned", keocacheData.spawned);
                collectionData.AddNode(FileIO.KEOCACHEDATA, data);
            }
            Log.Info("SaveCollectionToConfigNode, id: " + keoCache.keocacheCollectionData.collectionId);
            Log.Info("SaveCollectionToConfigNode, name: " + keoCache.keocacheCollectionData.name);
            Log.Info("SaveCollectionToConfigNode, title: " + keoCache.keocacheCollectionData.title);
            Log.Info("SaveCollectionToConfigNode, description: " + keoCache.keocacheCollectionData.description);

            KeoCacheCollection tmpK = LoadCollectionFromConfigNode(collectionData);

            return(collectionData);
            //fileNode.AddNode(FileIO.KEOCACHE_COLLECTION, collectionData);
            //return fileNode;
        }
        internal static KeoCacheCollection LoadCollectionFromConfigNode(ConfigNode loadedConfigNode)
        {
            Log.Info("LoadCollectionFromConfigNode");
            KeoCacheCollection keoCache = new KeoCacheCollection();

            //keoCache.keocacheCollectionData = new keoCacheCollectionData();

            loadedConfigNode.TryGetValue("id", ref keoCache.keocacheCollectionData.collectionId);
            loadedConfigNode.TryGetValue("name", ref keoCache.keocacheCollectionData.name);
            loadedConfigNode.TryGetValue("title", ref keoCache.keocacheCollectionData.title);
            loadedConfigNode.TryGetValue("author", ref keoCache.keocacheCollectionData.author);
#if false
            int    cnt = 0;
            string str = "";
            keoCache.keocacheCollectionData.description = "";
            while (cnt >= 0)
            {
                if (loadedConfigNode.HasValue("description-" + cnt.ToString()))
                {
                    loadedConfigNode.TryGetValue("description-" + cnt.ToString(), ref str);
                    if (keoCache.keocacheCollectionData.description != "")
                    {
                        keoCache.keocacheCollectionData.description += "\n";
                    }
                    keoCache.keocacheCollectionData.description += str;
                    cnt++;
                }
                else
                {
                    cnt = -1;
                }
            }
#endif
            FileIO.LoadTextArea("description", ref keoCache.keocacheCollectionData.description, ref loadedConfigNode);
            FileIO.LoadTextArea("initialHint", ref keoCache.keocacheCollectionData.initialHint, ref loadedConfigNode);



            loadedConfigNode.TryGetEnum <Difficulty>("difficulty", ref keoCache.keocacheCollectionData.difficulty, keoCache.keocacheCollectionData.difficulty);
            loadedConfigNode.TryGetValue("assignedTravelBug", ref keoCache.keocacheCollectionData.assignedTravelBug);

            Log.Info("LoadCollectionFromConfigNode, id: " + keoCache.keocacheCollectionData.collectionId);
            Log.Info("LoadCollectionFromConfigNode, name: " + keoCache.keocacheCollectionData.name);
            Log.Info("LoadCollectionFromConfigNode, title: " + keoCache.keocacheCollectionData.title);
            Log.Info("LoadCollectionFromConfigNode, description: " + keoCache.keocacheCollectionData.description);


            keoCache.keocacheCollectionData.requiredMods = loadedConfigNode.GetValuesList("requiredMod");
            loadedConfigNode.TryGetValue("lastCacheFound", ref keoCache.keocacheCollectionData.lastCacheFound);



            ConfigNode[] nodes = loadedConfigNode.GetNodes(FileIO.KEOCACHEDATA);
            Log.Info("nodes.count: " + nodes.Count());
            for (int i = 0; i < nodes.Length; i++)
            {
                ConfigNode   node         = nodes[i];
                KeoCacheData keocacheData = new KeoCacheData();

                node.TryGetValue("name", ref keocacheData.keoCacheName);
                node.TryGetValue("scienceNodeRequired", ref keocacheData.scienceNodeRequired);
                node.TryGetValue("found", ref keocacheData.found);

                Log.Info("LoadCollectionFromConfigNode.node, name: " + keocacheData.keoCacheName);
                Log.Info("LoadCollectionFromConfigNode.node, scienceNodeRequired: " + keocacheData.scienceNodeRequired);
                Log.Info("LoadCollectionFromConfigNode.node, found: " + keocacheData.found);

                string bodyName = "";
                node.TryGetValue("body", ref bodyName);
                // need to find celestial body and set keocacheData.body to it
                foreach (var p in PSystemManager.Instance.localBodies)
                {
                    if (p.name == bodyName)
                    {
                        keocacheData.body = p;
                        break;
                    }
                }
                int x = 0;
                node.TryGetValue("scale", ref x);
                keocacheData.scale = (Scale)x;

                double d = 0;
                node.TryGetValue("distance", ref d);
                keocacheData.distanceFromCache = d;
                keocacheData.absoluteDistance  = keocacheData.distanceFromCache;
                if (keocacheData.scale == Scale.km)
                {
                    keocacheData.absoluteDistance *= 1000;
                }

                node.TryGetValue("latitude", ref keocacheData.latitude);
                node.TryGetValue("longitude", ref keocacheData.longitude);

                FileIO.LoadTextArea("description", ref keocacheData.description, ref node);


                node.TryGetValue("lastHintFound", ref keocacheData.lastHintFound);

                var SavedHints = node.GetNodes(FileIO.HINT);
                keocacheData.hints = new List <Hint>();
                if (SavedHints != null)
                {
                    Log.Info("SavedHints.Count: " + SavedHints.Count());
                }
                foreach (var h in SavedHints)
                {
                    Hint hint = new Hint();
                    h.TryGetValue("hintTitle", ref hint.hintTitle);
                    d = 0;
                    h.TryGetValue("distance", ref d);
                    hint.hintDistance = d;
                    x = 0;
                    h.TryGetValue("scale", ref x);
                    hint.scale            = (Scale)x;
                    hint.absoluteDistance = hint.hintDistance;
                    if (hint.scale == Scale.km)
                    {
                        hint.absoluteDistance *= 1000;
                    }
                    x = 0;
                    h.TryGetValue("situations", ref x);
                    hint.situations = (Vessel.Situations)x;
                    h.TryGetValue("hint", ref hint.hint);

                    // h.TryGetValue("spawn", ref hint.spawn);
                    keocacheData.hints.Add(hint);
                }
                keocacheData.hints = keocacheData.hints.OrderByDescending(ad => ad.absoluteDistance).ToList();

                keocacheData.protoVessel = node.GetNode(FileIO.PROTOVESSEL);
                node.TryGetValue("spawned", ref keocacheData.spawned);
                //if (KeoCacheDriver.Instance != null && !KeoCacheDriver.Instance.useKeoCache)
                /* keocacheData.protoVessel = */
                //    VesselRespawn.Respawn(keocacheData.protoVessel);
                keoCache.keoCacheDataList.Add(keocacheData);
            }
            return(keoCache);
        }
        void GetActiveTravelBugs()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            Log.Info("GetActiveTravelBugs");
            Log.Info("FlightGlobals.Vessels.Count: " + FlightGlobals.Vessels.Count +
                     ", VesselsUnloaded.Count: " + FlightGlobals.VesselsUnloaded.Count +
                     ", VesselsLoaded.Count: " + FlightGlobals.VesselsLoaded.Count);
            activeTravelBugs = new Dictionary <string, TravelBugEntry>();
            usedKeoCaches    = new List <string>();

            for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
            {
                Vessel vessel = FlightGlobals.Vessels[i];
                //Log.Info("TravelBug_Window, i: " + i + ", vessel: " + vessel.GetDisplayName() + ",  loaded: " + vessel.loaded);
                // May need to use moduleHandlers here instead of partModules, needed if vessel is unloaded
                //
                //
                // if (moduleHandlers.ContainsKey(p.modules[i].moduleName)) {
                //
                if (vessel != null)
                {
                    if (!vessel.loaded)
                    {
                        for (int imh = vessel.protoVessel.protoPartSnapshots.Count - 1; imh >= 0; imh--)
                        {
                            ProtoPartSnapshot mh = vessel.protoVessel.protoPartSnapshots[imh];
                            for (int mi = mh.modules.Count - 1; mi >= 0; mi--)
                            {
                                ProtoPartModuleSnapshot module = mh.modules[mi];
                                if (module.moduleName == "KeoTravelBugModule")
                                {
                                    ConfigNode cn = module.moduleValues.GetNode(FileIO.KEOCACHE_COLLECTION);
                                    if (cn != null)
                                    {
                                        KeoCacheCollection tbKcc = KeoCacheCollection.LoadCollectionFromConfigNode(cn);
                                        if (tbKcc != null)
                                        {
                                            TravelBugEntry tbe = new TravelBugEntry(tbKcc.keocacheCollectionData.collectionId, vessel.vesselName, vessel.protoVessel.vesselID);

                                            activeTravelBugs.Add(tbe.keocachId, tbe);
                                        }
                                        FindKeoCaches();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        List <KeoTravelBugModule> vesselTravelBugs = vessel.FindPartModulesImplementing <KeoTravelBugModule>();

                        if (vesselTravelBugs != null)
                        {
                            Log.Info("vesselTravelBugs.count: " + vesselTravelBugs.Count);
                            for (int i1 = vesselTravelBugs.Count - 1; i1 >= 0; i1--)
                            {
                                KeoTravelBugModule traveBug = vesselTravelBugs[i1];
                                Log.Info("creating TravelBugentry # " + i1);
                                if (traveBug == null)
                                {
                                    Log.Info("traveBug is null");
                                }
                                if (traveBug.tbKcc != null)
                                {
                                    if (traveBug.tbKcc == null)
                                    {
                                        Log.Info("traveBug.tbKcc is null");
                                    }
                                    if (traveBug.tbKcc.keocacheCollectionData == null)
                                    {
                                        Log.Info("traveBug.tbKcc.keocacheCollectionData is null");
                                    }
                                    if (traveBug.tbKcc.keocacheCollectionData.collectionId == null)
                                    {
                                        Log.Info("traveBug.tbKcc.keocacheCollectionData.collectionId is null");
                                    }

                                    if (vessel == null)
                                    {
                                        Log.Info("vessel is null");
                                    }
                                    if (vessel.vesselName == null)
                                    {
                                        Log.Info("vessel.vesselName is null");
                                    }
                                    if (vessel.protoVessel == null)
                                    {
                                        Log.Info("vessel.protoVessel is null");
                                    }

                                    TravelBugEntry tbe = new TravelBugEntry(traveBug.tbKcc.keocacheCollectionData.collectionId, vessel.vesselName, vessel.protoVessel.vesselID);

                                    activeTravelBugs.Add(tbe.keocachId, tbe);
                                    FindKeoCaches();
                                }
                            }
                        }
                    }
                }
            }
        }
        void TravelBug_Window(int id)
        {
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Width(10);
            GUILayout.Label("Vessel", GUILayout.Width(175));
            GUILayout.Space(5);
            GUILayout.Label("Collection Name", GUILayout.Width(175));
            GUILayout.Space(5);
            GUILayout.Label("Collection Title", GUILayout.Width(175));
            GUILayout.EndHorizontal();

            //
            // If this starts to be inefficient, then a new method to gather all the travelbugs will need
            // to be written. that method will be called when this window is opened
            //
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(120), GUILayout.Width(615));
            for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
            {
                Vessel vessel = FlightGlobals.Vessels[i];
                Log.Info("TravelBug_Window, i: " + i + ", vessel: " + vessel.GetDisplayName() + ",  loaded: " + vessel.loaded);
                // May need to use moduleHandlers here instead of partModules, needed if vessel is unloaded
                //
                //
                // if (moduleHandlers.ContainsKey(p.modules[i].moduleName)) {
                //
                if (!vessel.loaded)
                {
                    for (int imh = vessel.protoVessel.protoPartSnapshots.Count - 1; imh >= 0; imh--)
                    {
                        Log.Info("imh: " + imh);
                        ProtoPartSnapshot mh = vessel.protoVessel.protoPartSnapshots[imh];
                        for (int mi = mh.modules.Count - 1; mi >= 0; mi--)
                        {
                            Log.Info("mi: " + mi);
                            ProtoPartModuleSnapshot module = mh.modules[mi];
                            if (module.moduleName == "KeoTravelBugModule")
                            {
                                ConfigNode cn = module.moduleValues.GetNode(FileIO.KEOCACHE_COLLECTION);
                                if (cn != null)
                                {
                                    KeoCacheCollection tbKcc = KeoCacheCollection.LoadCollectionFromConfigNode(cn);
                                    if (tbKcc != null)
                                    {
                                        DisplayTravelBugData(
                                            vessel.protoVessel.vesselID,
                                            vessel.vesselName,
                                            tbKcc.keocacheCollectionData.name,
                                            tbKcc.keocacheCollectionData.title);
                                    }
                                }

#if false
                                if (KeoScenario.activeKeoCacheCollections != null)
                                {
                                    string collectionId = module.moduleValues.GetValue("collectionID");
                                    Log.Info("collectionID: " + collectionId);
                                    activeKeoCacheCollection = KeoScenario.activeKeoCacheCollections[collectionId];

                                    if (activeKeoCacheCollection != null)
                                    {
                                        DisplayTravelBugData(
                                            vessel.protoVessel.vesselID,
                                            vessel.vesselName,
                                            activeKeoCacheCollection.keocacheCollectionData.name,
                                            activeKeoCacheCollection.keocacheCollectionData.title);
                                    }
                                }
#endif
                            }
                        }
                    }
                }
                else
                {
                    List <KeoTravelBugModule> vesselTravelBugs = vessel.FindPartModulesImplementing <KeoTravelBugModule>();

                    if (vesselTravelBugs != null)
                    {
                        for (int i1 = vesselTravelBugs.Count - 1; i1 >= 0; i1--)
                        {
                            KeoTravelBugModule traveBug = vesselTravelBugs[i1];

                            var c = traveBug.collectionID;
                            DisplayTravelBugData(vessel.id, vessel.vesselName, traveBug.tbKcc.keocacheCollectionData.name, traveBug.tbKcc.keocacheCollectionData.title);

#if false
                            if (KeoScenario.activeKeoCacheCollections != null)
                            {
                                activeKeoCacheCollection = KeoScenario.activeKeoCacheCollections[c];

                                if (activeKeoCacheCollection != null)
                                {
                                    DisplayTravelBugData(vessel.id, vessel.vesselName, activeKeoCacheCollection.keocacheCollectionData.name, activeKeoCacheCollection.keocacheCollectionData.title);
                                }
                            }
#endif
                        }
                    }
                }
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndScrollView();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close", GUILayout.Width(60)))
            {
                visibleTravelBug = false;
                visibleMenu      = true;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

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