public void AddToCollection() { Log.Info("KeoCacheModule.AddToCollection"); Events["AddToCollection"].guiActive = false; Events["RemoveFromCollection"].guiActive = true; KeoCacheData data = new KeoCacheData(); data.keoCacheName = this.vessel.name; int idxLeftParen = data.keoCacheName.LastIndexOf('('); if (idxLeftParen > 0) { int idxRightParen = data.keoCacheName.LastIndexOf(')'); if (idxRightParen > idxLeftParen) { data.keoCacheName = data.keoCacheName.Substring(idxLeftParen + 1, idxRightParen - (idxLeftParen + 1)); } } data.keoCacheName = "Location of " + data.keoCacheName; data.CacheVessel = this.vessel; data.latitude = this.vessel.latitude; data.longitude = this.vessel.longitude; assigned = AssignStatus.assigned; this.keocacheId = data.keocacheId; collectionId = KeoCacheDriver.activeKeoCacheCollection.keocacheCollectionData.collectionId; KeoCacheDriver.activeKeoCacheCollection.keoCacheDataList.Add(data); UpdateEvents(); }
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 DisplayCollectionCaches() { GUILayout.BeginHorizontal(); #if false GUIStyle labelStyle = labelNormal; if (activeKeoCacheCollection.keoCacheDataList.Count == 0) { labelStyle = labelRed; } #endif GUILayout.Label("KeoCaches"); //, labelStyle); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); scrollPos2 = GUILayout.BeginScrollView(scrollPos2, GUILayout.MinHeight(60), GUILayout.Width(300), GUILayout.MaxHeight(200)); int indexToMove = -1, indexToMoveTo = -1; KeoCacheData itemToMove = null; KeoCacheData itemToDelete = null; for (int i = 0; i < activeKeoCacheCollection.keoCacheDataList.Count; i++) { KeoCacheData g = activeKeoCacheCollection.keoCacheDataList[i]; saveable = saveable & !SetBackground(g.hints.Count == 0 || g.description == ""); if (g.hints.Count == 0 || g.description == "") { saveable = false; } GUILayout.BeginHorizontal(); if (GUILayout.Button(g.keoCacheName)) { activeKeoCacheData = g; newKeoCacheData = false; visibleKeoCache = true; } SetBackground(false); GUILayout.BeginVertical(GUILayout.Width(15)); GUILayout.Space(3); if (i == 0) { GUI.enabled = false; } if (GUILayout.Button(upContent, arrowButtonStyle)) { indexToMove = i; indexToMoveTo = i - 1; itemToMove = g; } if (i < activeKeoCacheCollection.keoCacheDataList.Count - 1) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUILayout.Button(downContent, arrowButtonStyle)) { indexToMove = i; indexToMoveTo = i + 1; itemToMove = g; } GUILayout.EndVertical(); GUI.enabled = true; if (GUILayout.Button("X", redButton, GUILayout.Width(20))) { itemToDelete = g; } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndHorizontal(); if (itemToDelete != null) { activeKeoCacheCollection.keoCacheDataList.Remove(itemToDelete); itemToDelete.DeleteVessel(); itemToDelete.hints.Clear(); } if (indexToMove != -1) { activeKeoCacheCollection.keoCacheDataList.Remove(itemToMove); activeKeoCacheCollection.keoCacheDataList.Insert(indexToMoveTo, itemToMove); } }
void FixedUpdate() { if (HighLogic.LoadedSceneIsFlight) { if (this.vessel == FlightGlobals.ActiveVessel) { //Log.Info("FixedUpdate, collectionID: " + collectionID); if (tbKcc == null) { //Log.Info("tbKcc is null"); return; } else { Log.Info("tbKcc " + tbKcc.keocacheCollectionData.collectionId); } #if false if (!KeoScenario.activeKeoCacheCollections.ContainsKey(collectionID)) { return; } #endif int currentCache = tbKcc.keocacheCollectionData.lastCacheFound + 1; if (tbKcc.keoCacheDataList.Count <= currentCache) { return; } int currentHint = tbKcc.keoCacheDataList[currentCache].lastHintFound + 1; Log.Info("lastCacheFound: " + tbKcc.keocacheCollectionData.lastCacheFound + ", lastHintFound: " + tbKcc.keoCacheDataList[currentCache].lastHintFound); KeoCacheData kcd = tbKcc.keoCacheDataList[currentCache]; if (kcd.body == FlightGlobals.currentMainBody) { double spawnDistance = 0; double hintDistance = 0; float lat = 0, lon = 0, alt = 0; kcd.protoVessel.TryGetValue("lat", ref lat); kcd.protoVessel.TryGetValue("lon", ref lon); kcd.protoVessel.TryGetValue("alt", ref alt); float d = GetStraightDistance(lat, lon, alt); //if (tbKcc.keoCacheDataList[currentCache].hints[currentHint].scale == Scale.km) // d /= 1000; Log.Info("distance: " + d); if (currentCache < tbKcc.keoCacheDataList.Count) { spawnDistance = tbKcc.keoCacheDataList[currentCache].absoluteDistance; } if (currentHint < tbKcc.keoCacheDataList[currentCache].hints.Count) { hintDistance = tbKcc.keoCacheDataList[currentCache].hints[currentHint].absoluteDistance; } #if false Log.Info("hintDistance: " + hintDistance + ", spawnDistance: " + spawnDistance); Log.Info("currentCache: " + currentCache + ", currentHint: " + currentHint); Log.Info("KeoScenario.activeKeoCacheCollections[collectionID].keoCacheDataList[currentCache].hints[currentHint].distance: " + tbKcc.keoCacheDataList[currentCache].hints[currentHint].distance); Log.Info("KeoScenario.activeKeoCacheCollections[collectionID].keoCacheDataList[currentCache].hints.Count: " + tbKcc.keoCacheDataList[currentCache].hints.Count); #endif if (d <= hintDistance) { bool landed = (Vessel.Situations.LANDED & tbKcc.keoCacheDataList[currentCache].hints[currentHint].situations) > 0; bool splashed = (Vessel.Situations.SPLASHED & tbKcc.keoCacheDataList[currentCache].hints[currentHint].situations) > 0; bool flying = (Vessel.Situations.FLYING & tbKcc.keoCacheDataList[currentCache].hints[currentHint].situations) > 0; if (landed || splashed || flying) { Log.Info("Crossed currentHint.distance, currentHint: " + currentHint); if (currentHint < tbKcc.keoCacheDataList[currentCache].hints.Count) { tbKcc.keoCacheDataList[currentCache].lastHintFound++; displayCurrentHint = true; if (HighLogic.CurrentGame.Parameters.CustomParams <KeoCacheOptions>().pauseAtNewHint) { FlightDriver.SetPause(true, false); } } } } if (d <= spawnDistance && tbKcc.keoCacheDataList[currentCache].lastHintFound == tbKcc.keoCacheDataList[currentCache].hints.Count - 1) { if (!kcd.spawned) { Log.Info("Spawning KeoCache"); VesselRespawn.Respawn(kcd.protoVessel); kcd.spawned = true; } tbKcc.keoCacheDataList[currentCache].lastHintFound++; } } } } }
void DisplayCollectionButtons() { if (!visibleActiveCollectionsReadOnly) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Load Collection", buttonWidth)) { StartLoadDialog(ParentWin.collection, collectionWinRect); } GUILayout.FlexibleSpace(); if (!saveable) { GUI.enabled = false; } if (GUILayout.Button("Save Collection", buttonWidth)) { FileIO.SaveKeoCacheFile(activeKeoCacheCollection); CloseKeoCacheWindow(); } GUI.enabled = true; GUILayout.FlexibleSpace(); if (GUILayout.Button("Close without saving", buttonWidth)) { CloseKeoCacheWindow(); } GUILayout.FlexibleSpace(); //GUILayout.EndHorizontal(); //GUILayout.BeginHorizontal(); //GUILayout.FlexibleSpace(); if (!visibleActiveCollectionsReadOnly) { saveable = saveable & activeKeoCacheCollection.keoCacheDataList.Count > 0; if (GUILayout.Button("New KeoCache", activeKeoCacheCollection.keoCacheDataList.Count == 0 ? redButton : normalButton, buttonWidth)) { visibleKeoCache = true; activeKeoCacheData = new KeoCacheData(); newKeoCacheData = true; //LaunchEvent(); //StartCoroutine(WaitForSpawn()); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } } else { GUILayout.FlexibleSpace(); if (GUILayout.Button("Close", buttonWidth)) { CloseKeoCacheWindow(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Select", buttonWidth)) { SelectKeoCacheForBug(activeKeoCacheCollection.fullPath); CloseKeoCacheWindow(); } GUILayout.FlexibleSpace(); } }