internal void Copy(Hint oldHint) { hintDistance = oldHint.hintDistance; hint = oldHint.hint; hintTitle = oldHint.hintTitle; scale = oldHint.scale; situations = oldHint.situations; absoluteDistance = oldHint.absoluteDistance; // spawn = oldHint.spawn; }
internal Hint Copy() { Hint newHint = new Hint(); newHint.hintDistance = hintDistance; newHint.hint = hint; newHint.hintTitle = hintTitle; newHint.scale = scale; newHint.situations = situations; newHint.absoluteDistance = absoluteDistance; // newHint.spawn = spawn; return(newHint); }
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); }
//Draws the export screen, complete with a hint editor internal void DrawExportScreen() { //User has to log in to export anything //api.login(); GUILayout.BeginHorizontal(); CenteredLabel("Export the current vessel"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); //creates vertically aligned column GUILayout.BeginVertical(); //first column GUILayout.Label("Title:"); GUILayout.Label("Description:"); GUILayout.Label("Difficulty:"); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); //second column title = GUILayout.TextField(title); description = GUILayout.TextArea(description); GUILayout.BeginHorizontal(); if (GUILayout.Button("<<")) { int currDiff = (int)difficulty; if (currDiff == 0) { difficulty = Difficulty.Insane; } else { currDiff--; difficulty = (Difficulty)currDiff; } } CenteredLabel(difficulty.ToString()); if (GUILayout.Button(">>")) { int currDiff = (int)difficulty; if (currDiff == 3) { difficulty = Difficulty.Easy; } else { currDiff++; difficulty = (Difficulty)currDiff; } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(20.0f * (Screen.height / 1920f)); //space between overview and hints GUILayout.BeginHorizontal(); CenteredLabel("Hints"); GUILayout.EndHorizontal(); if (!addingHint) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Title"); foreach (Hint h in hintList) { GUILayout.Label(h.hintTitle); } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Hint"); foreach (Hint h in hintList) { GUILayout.Label(h.hint, GUILayout.MaxWidth(100 * (Screen.width / 1920))); } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Distance"); foreach (Hint h in hintList) { //Should print the distance to 2 decimal places with the scale after it GUILayout.Label(string.Format("{0:0.00}", h.hintDistance) + h.scale.ToString()); } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Edit"); for (int i = 0; i < hintList.Count; i++) { if (GUILayout.Button("", GUILayout.MaxWidth(20 * (Screen.width / 1920)))) { editingHint = hintList[i]; addingHint = true; editingMode = EditMode.Edit; break; } } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Delete"); short ih = 0; while (ih < hintList.Count) { if (GUILayout.Button("", GUILayout.MaxWidth(20 * (Screen.width / 1920)))) { hintList.RemoveAt(ih); } else { ih++; } } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add new hint")) { addingHint = !addingHint; editingMode = EditMode.CreateNew; } if (GUILayout.Button("Export geocache")) { } if (GUILayout.Button("Close", GUILayout.Width(60))) { KeoCacheDriver.Instance.showKerbalX = false; } } else { if (editingHint == null) { editingHint = new Hint(); } GUILayout.BeginHorizontal(); CenteredLabel("Hint editor"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Title"); GUILayout.FlexibleSpace(); editingHint.hintTitle = GUILayout.TextField(editingHint.hintTitle, GUILayout.MinWidth(250 * (Screen.width / 1080))); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Hint"); GUILayout.FlexibleSpace(); editingHint.hint = GUILayout.TextArea(editingHint.hint, GUILayout.MinWidth(250 * (Screen.width / 1080))); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Distance"); GUILayout.FlexibleSpace(); double d = 0; bool b = double.TryParse(editingHintDistance, out d); if (!b) { GUI.contentColor = Color.red; } else { editingHint.hintDistance = d; } editingHintDistance = GUILayout.TextField(editingHintDistance, GUILayout.MinWidth(225 * (Screen.width / 1080))); GUI.contentColor = originalColor; scalesIndex = GUILayout.Toolbar(scalesIndex, scales); if (scalesIndex == 0) { editingHint.scale = Scale.m; } else { editingHint.scale = Scale.km; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Save hint")) { if (editingMode == EditMode.CreateNew) { hintList.Add(editingHint); } editingHint = null; addingHint = !addingHint; } if (GUILayout.Button("Cancel")) { editingHint = null; addingHint = !addingHint; } GUILayout.EndHorizontal(); } GUILayout.Space(20.0f * (Screen.height / 1920f)); //space at the bottom }
void KeoCache_Window(int windowId) { saveable = true; if (activeKeoCacheData.CacheVessel == null || activeKeoCacheData.keoCacheName == "") { saveable = false; } GUILayout.BeginHorizontal(); GUILayout.Label("Name:"); //, activeKeoCacheData.keoCacheName == "" ? labelRed : labelNormal); SetBackground(activeKeoCacheData.keoCacheName.Length == 0); activeKeoCacheData.keoCacheName = GUILayout.TextField(activeKeoCacheData.keoCacheName); SetBackground(false); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Science Node Required:"); activeKeoCacheData.scienceNodeRequired = GUILayout.TextField(activeKeoCacheData.scienceNodeRequired); GUILayout.EndHorizontal(); if (activeKeoCacheData.body != null) { GUILayout.BeginHorizontal(); GUILayout.Label("Celestial body:"); GUILayout.TextField(activeKeoCacheData.body.displayName.Substring(0, activeKeoCacheData.body.displayName.Length - 2)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Latitude:"); /*activeKeoCacheData.latitude = */ GUILayout.TextField(Util.Latitude_Coordinates(activeKeoCacheData.latitude)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Longitude:"); /*activeKeoCacheData.longitude = */ GUILayout.TextField(Util.Longitude_Coordinates(activeKeoCacheData.longitude)); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Description:"); SetBackground(activeKeoCacheData.description.Length == 0); activeKeoCacheData.description = GUILayout.TextArea(activeKeoCacheData.description, GUILayout.Height(75), GUILayout.Width(300)); SetBackground(false); GUILayout.EndHorizontal(); #if false GUILayout.BeginHorizontal(); GUILayout.Label("nextKeocacheId:"); activeKeoCacheData.nextKeocacheId = GUILayout.TextField(activeKeoCacheData.nextKeocacheId); GUILayout.EndHorizontal(); #endif saveable = (activeKeoCacheData.hints.Count > 0); if (activeKeoCacheData.hints.Count > 0) { int i = activeKeoCacheData.hints.Count - 1; double d1 = activeKeoCacheData.hints[i].absoluteDistance; if (activeKeoCacheData.hints[i].scale == Scale.km) { d1 *= 1000; } double d2 = activeKeoCacheData.absoluteDistance; SetBackground(d1 <= d2); } double d = 0; Scale sc = 0; ShowGetProximity("KeoCache Vessel", ref d, ref activeKeoCacheData.absoluteDistance, ref sc); activeKeoCacheData.distanceFromCache = d; activeKeoCacheData.scale = sc; SetBackground(false); GUILayout.BeginHorizontal(); GUILayout.Label("Hints:"); Hint toDelete = null; scrollPos3 = GUILayout.BeginScrollView(scrollPos3, GUILayout.MinHeight(60), GUILayout.Width(300), GUILayout.MaxHeight(200)); for (int g1 = 0; g1 < activeKeoCacheData.hints.Count; g1++) { var g = activeKeoCacheData.hints[g1]; GUILayout.BeginHorizontal(); if (GUILayout.Button(g.hintTitle + ", proximity: " + g.hintDistance.ToString("N0") + " " + g.scale.ToString())) { activeHint = g.Copy(); origHint = g; editHint = true; visibleHint = true; } if (GUILayout.Button("X", redButton, GUILayout.Width(20))) { toDelete = g; } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndHorizontal(); if (toDelete != null) { activeKeoCacheData.hints.Remove(toDelete); } //GUILayoutOption buttonWidth = GUILayout.Width(150); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add Hint", activeKeoCacheData.hints.Count == 0?redButton:normalButton, buttonWidth)) { visibleHint = true; editHint = false; activeHint = new Hint(); } GUILayout.FlexibleSpace(); if (activeKeoCacheData.CacheVessel != null) { if (GUILayout.Button("Delete Cache Vessel", buttonWidth)) { activeKeoCacheData.DeleteVessel(); } } else { if (GUILayout.Button("Place Cache Vessel", redButton, buttonWidth)) { LaunchEvent(); StartCoroutine(WaitForSpawn()); } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Cancel", buttonWidth)) { visibleKeoCache = false; } GUILayout.FlexibleSpace(); if (!saveable) { GUI.enabled = false; } if (GUILayout.Button("Save and Close", buttonWidth)) { visibleKeoCache = false; if (newKeoCacheData) { Part part = activeKeoCacheData.CacheVessel.Parts[0]; KeoCacheModule partmod = part.FindModuleImplementing <KeoCacheModule>(); Log.Info("SaveAndClose"); Log.Info("part.craftID: " + part.craftID); partmod.UpdateData(activeKeoCacheData.keocacheId, KeoCacheModule.AssignStatus.assigned, activeKeoCacheCollection.keocacheCollectionData.collectionId); activeKeoCacheCollection.keoCacheDataList.Add(activeKeoCacheData); } } GUI.enabled = true; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUI.DragWindow(); }