private static ImpactScienceData createSpectralData(CelestialBody crashBody, Vessel crashVessel, uint flightID) { double crashVelocity = crashVessel.srf_velocity.magnitude; Log("Velocity=" + crashVelocity); float crashMasss = crashVessel.GetTotalMass() * 1000; double crashEnergy = 0.5 * crashMasss * crashVelocity * crashVelocity; //KE of crash ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment("ImpactSpectrometer"); String biome = ScienceUtil.GetExperimentBiome(crashBody, crashVessel.latitude, crashVessel.longitude); CBAttributeMapSO m = crashBody.BiomeMap; CBAttributeMapSO.MapAttribute[] atts = m.Attributes; ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, ExperimentSituations.InSpaceLow, crashBody, biome, biome); double science = subject.scienceCap; Log("Impact took place in " + biome + " at " + crashVessel.latitude + "," + crashVessel.longitude); String flavourText = "Impact at <<1>> on <<2>>"; science = Math.Max(0, science - subject.science); science /= subject.subjectValue; ImpactScienceData data = new ImpactScienceData(ImpactScienceData.DataTypes.Spectral, 0, biome, crashVessel.latitude, (float)(science * subject.dataScale), 1f, 0, subject.id, Localizer.Format(flavourText, biome, crashBody.GetDisplayName()), false, flightID); ScreenMessages.PostScreenMessage( Localizer.Format("#autoLOC_Screen_Spectrum", biome, crashBody.GetDisplayName()), 5.0f, ScreenMessageStyle.UPPER_RIGHT); return(data); }
public static string GetCurrentBiomeName(Vessel vessel) { CBAttributeMapSO biomeMap = FlightGlobals.currentMainBody.BiomeMap; CBAttributeMapSO.MapAttribute mapAttribute = biomeMap.GetAtt(vessel.latitude * Mathf.Deg2Rad, vessel.longitude * Mathf.Deg2Rad); return(mapAttribute.name); }
public static int GetBiomeIndex(CelestialBody body, double lat, double lon) { int currentBiomeIndex = -1; if (body.BiomeMap != null) { CBAttributeMapSO biomeMap = body.BiomeMap; // CBAttributeMapSO.GetAtt lon -= Math.PI / 2.0; lon = UtilMath.WrapAround(lon, 0.0, Math.PI * 2.0); double y = lat * (1.0 / Math.PI) + 0.5; double x = 1.0 - lon * 0.15915494309189535; Color pixelColor = biomeMap.GetPixelColor(x, y); currentBiomeIndex = 0; // this is mandatory because the first biome is a used as fallback in the stock code (!) float currentSqrMag = float.MaxValue; for (int i = 0; i < biomeMap.Attributes.Length; i++) { if (!biomeMap.Attributes[i].notNear) { float sqrMag = RGBColorSqrMag(pixelColor, biomeMap.Attributes[i].mapColor); if (sqrMag < currentSqrMag && (biomeMap.nonExactThreshold == -1f || sqrMag < biomeMap.nonExactThreshold)) { currentBiomeIndex = i; currentSqrMag = sqrMag; } } } } return(currentBiomeIndex); }
// This function generates the biomes for the planet. (Coupled with an // appropriate Texture2D.) public static CBAttributeMapSO GenerateCBAttributeMapSO(string name) { Debug.Log("[Kopernicus] GenerateCBAttributeMapSO begins r4"); CBAttributeMapSO rv = ScriptableObject.CreateInstance <CBAttributeMapSO>(); Texture2D map = new Texture2D(4, 4, TextureFormat.RGB24, false); Debug.Log("[Kopernicus] map=" + map); map.LoadImage(System.IO.File.ReadAllBytes(KSPUtil.ApplicationRootPath + PluginDirectory + "/Planets/" + name + "/Biomes.png")); //map.Compress(true); // This might make the edges funny. map.Compress(false); // If it will let us take in an indexed color PNG that would be preferable - bcs map.Apply(true, false); rv.CreateMap(MapSO.MapDepth.RGB, map); //rv.nonExactThreshold = -1f; // This will theoretically return the "best match". It also depends on float comparison, but at least it's to a constant. rv.nonExactThreshold = 0.05f; // 0.6 0.0 0.4 matches 1 0 0 at .33 so .1 is fairly generous and should be reduced for maps with many colors // "exact" match is a broken concept (floats should never be compared to floats with == or !=) and (as implemented as of KSP .24.2) should // never be used. rv.exactSearch = false; rv.Attributes = new CBAttributeMapSO.MapAttribute[3]; rv.Attributes[0] = new CBAttributeMapSO.MapAttribute(); rv.Attributes[0].name = "PolarCaps"; rv.Attributes[0].value = 1.5f; rv.Attributes[0].mapColor = new Color(0f, 1f, 0f); rv.Attributes[1] = new CBAttributeMapSO.MapAttribute(); rv.Attributes[1].name = "Mares"; rv.Attributes[1].value = 1.0f; rv.Attributes[1].mapColor = new Color(0f, 0f, 1f); rv.Attributes[2] = new CBAttributeMapSO.MapAttribute(); rv.Attributes[2].name = "Dunes"; rv.Attributes[2].value = 1.0f; rv.Attributes[2].mapColor = new Color(1f, 0f, 0f); //rv.defaultAttribute = rv.Attributes [0]; /* * // Troubleshooting fosssil * Vector4 pixelBilinear; * Vector4 color; * for (float lat = -3f; lat < 3f; lat += .1f) * for (float lon = 0f; lon < 6f; lon += .1f) { * float innerlon = lon - 1.5707963267948966f; * * float v = (float)(lat / 3.1415926535897931) + 0.5f; * float u = (float)(innerlon / 6.2831853071795862f); * pixelBilinear = rv.Map.GetPixelBilinear (u, v); * color = rv.Attributes [2].mapColor; * * * Debug.Log ("X<A "+ lat + " "+lon+" clr="+ color + " pbl=" + pixelBilinear+" rv=" + rv.GetAtt (lat, lon).name + ":" + * (color-pixelBilinear).sqrMagnitude); * } */ Debug.Log("[Kopernicus] GenerateCBAttributeMapSO ends"); return(rv); }
/// <summary>Gets the biome of the current colliding part.</summary> /// <param name="lat">Latitude of the vessel.</param> /// <param name="lon">Longitude of the vessel.</param> /// <returns>The name of the biome it finds.</returns> static string GetCurrentBiomeName(double lat, double lon) { CBAttributeMapSO biomeMap = FlightGlobals.currentMainBody.BiomeMap; CBAttributeMapSO.MapAttribute mapAttribute = biomeMap.GetAtt(lat * Mathf.Deg2Rad, lon * Mathf.Deg2Rad); string result = mapAttribute.name.Replace(' ', '_'); return(result); }
public static int GenerateAbundanceSeed(AbundanceRequest request, CBAttributeMapSO.MapAttribute biome, CelestialBody body) { var seed = RegolithScenario.Instance.gameSettings.Seed; seed *= (request.BodyId + 1); seed += request.ResourceName.Length * request.ResourceName.Substring(1).ToCharArray().First(); seed += body.bodyName.Length * body.bodyName.Substring(1).ToCharArray().First(); if (biome != null) { seed += Convert.ToInt32(biome.mapColor.grayscale * 4096) * ((int)request.ResourceType + 1); } return seed; }
private void listBiomes(CelestialBody body) { //todo temporary Log("attname=" + body.bodyName); CBAttributeMapSO m = body.BiomeMap; CBAttributeMapSO.MapAttribute[] atts = m.Attributes; foreach (CBAttributeMapSO.MapAttribute att in atts) { Log("att=" + att.name + "-" + att.value); } foreach (CelestialBody sub in body.orbitingBodies) { listBiomes(sub); } }
protected override void Inspect(Vessel vessel) { if (vessel != null) { double lat = vessel.latitude * Math.PI / 180d; double lon = vessel.longitude * Math.PI / 180d; CelestialBody body = vessel.mainBody; if (body != null) { CBAttributeMapSO biomeMap = body.BiomeMap; if (biomeMap != null) { mapAttribute = biomeMap.GetAtt(lat, lon); } } } }
private void prepareBiome() { CBAttributeMapSO.MapAttribute mapAttribute; try { Vessel vessel = FlightGlobals.ActiveVessel; CBAttributeMapSO BiomeMap = vessel.mainBody.BiomeMap; double lat = vessel.latitude * Math.PI / 180d; double lon = vessel.longitude * Math.PI / 180d; mapAttribute = BiomeMap.GetAtt(lat, lon); } catch (NullReferenceException) { mapAttribute = new CBAttributeMapSO.MapAttribute(); mapAttribute.name = "N/A"; } this.biome.value = mapAttribute.name; }
// Get reference to existing biome descriptor public Biome(CBAttributeMapSO.MapAttribute attribute) { this.attribute = attribute; }
public static CBAttributeMapSO.MapAttribute GetBiome(this Vessel vessel) { CBAttributeMapSO.MapAttribute mapAttribute; try { CBAttributeMapSO BiomeMap = vessel.mainBody.BiomeMap; double lat = vessel.latitude * Math.PI / 180d; double lon = vessel.longitude * Math.PI / 180d; mapAttribute = BiomeMap.GetAtt(lat, lon); /* * lon -= Math.PI / 2d; * * if (lon < 0d) * { * lon += 2d * Math.PI; * } * * float v = (float)(lat / Math.PI) + 0.5f; * float u = (float)(lon / (2d * Math.PI)); * * Color pixelBilinear = BiomeMap.Map.GetPixelBilinear(u, v); * mapAttribute = BiomeMap.defaultAttribute; * * if (BiomeMap.Map != null) * { * if (BiomeMap.exactSearch) * { * for (int i = 0; i < BiomeMap.Attributes.Length; ++i) * { * if (pixelBilinear == BiomeMap.Attributes[i].mapColor) * { * mapAttribute = BiomeMap.Attributes[i]; * } * } * } * else * { * float zero = 0; * float num = 1 / zero; * for (int j = 0; j < BiomeMap.Attributes.Length; ++j) * { * Color mapColor = BiomeMap.Attributes[j].mapColor; * float sqrMagnitude = ((Vector4)(mapColor - pixelBilinear)).sqrMagnitude; * if (sqrMagnitude < num) * { * bool testCase = true; * if (BiomeMap.nonExactThreshold != -1) * { * testCase = (sqrMagnitude < BiomeMap.nonExactThreshold); * } * if (testCase) * { * mapAttribute = BiomeMap.Attributes[j]; * num = sqrMagnitude; * } * } * } * } * } */ } catch (NullReferenceException) { mapAttribute = new CBAttributeMapSO.MapAttribute(); mapAttribute.name = "N/A"; } return(mapAttribute); }
/// <summary> /// Renders an editor for the object /// </summary> protected void RenderObject(Object @object) { // Null check if (@object == null) { return; } // Get all parseable MemberInfos MemberInfo[] infos = @object.GetType().GetMembers() .Where(m => m.MemberType == MemberTypes.Field || m.MemberType == MemberTypes.Property) .Where(m => !(m as FieldInfo)?.IsLiteral ?? true) .Where(m => m is PropertyInfo ? (m as PropertyInfo).CanRead && (m as PropertyInfo).CanWrite : true) .ToArray(); // Loop through all fields and display them foreach (MemberInfo info in infos) { // Get the type and the value of the member Type FieldType = info.GetMemberType(); Object value = info.GetValue(@object); if (FieldType == typeof(String)) { Label(info.Name); index--; TextField(value.ToString(), v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(Boolean)) { Label(info.Name); index--; TextField((Boolean)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(Int32)) { Label(info.Name); index--; TextField((Int32)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(Single)) { Label(info.Name); index--; TextField((Single)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(Double)) { Label(info.Name); index--; TextField((Double)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20)); } else if (value is Enum) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Enum, value, c => info.SetValue(@object, c)); UIController.Instance.EnableWindow(KittopiaWindows.Enum); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(Color)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_COLOR, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Color, (Color)value, c => info.SetValue(@object, c)); UIController.Instance.EnableWindow(KittopiaWindows.Color); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(Vector3)) { Label(info.Name); index--; Vector3 value_ = (Vector3)value; TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--; TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(260, index * distance + 10, 50, 20)); index--; TextField(value_.z, f => { value_.z = f; info.SetValue(@object, value_); }, new Rect(320, index * distance + 10, 50, 20)); } else if (FieldType == typeof(Vector3d)) { Label(info.Name); index--; Vector3d value_ = (Vector3d)value; TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--; TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(260, index * distance + 10, 50, 20)); index--; TextField(value_.z, f => { value_.z = f; info.SetValue(@object, value_); }, new Rect(320, index * distance + 10, 50, 20)); } else if (FieldType == typeof(Vector2)) { Label(info.Name); index--; Vector2 value_ = (Vector2)value; TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--; TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(285, index * distance + 10, 50, 20)); } else if (FieldType == typeof(Vector2d)) { Label(info.Name); index--; Vector2d value_ = (Vector2d)value; TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--; TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(285, index * distance + 10, 50, 20)); } else if (FieldType == typeof(CBAttributeMapSO)) { // Load the MapSO Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_LOAD_CBMAP, () => { FileWindow.type = FieldType; UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location => { if (File.Exists(location)) { String path = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, ""); Texture2D texture = Utility.LoadTexture(path, false, false, false); texture.name = path.Replace("\\", "/"); CBAttributeMapSO mapSO = ScriptableObject.CreateInstance <CBAttributeMapSO>(); mapSO.exactSearch = false; mapSO.nonExactThreshold = 0.05f; mapSO.CreateMap(MapSO.MapDepth.RGB, texture); mapSO.Attributes = (value as CBAttributeMapSO).Attributes; mapSO.name = path.Replace("\\", "/"); info.SetValue(@object, mapSO); } else { info.SetValue(@object, Resources.FindObjectsOfTypeAll <CBAttributeMapSO>().FirstOrDefault(m => m.name == location)); } }); UIController.Instance.EnableWindow(KittopiaWindows.Files); }, new Rect(200, index * distance + 10, 170, 20)); // Edit the Biome-Definitions Button(Localization.LOC_KITTOPIATECH_EDIT_BIOMES, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Biome, (value as CBAttributeMapSO).Attributes, att => { (value as CBAttributeMapSO).Attributes = att; info.SetValue(@object, value); }); UIController.Instance.EnableWindow(KittopiaWindows.Biome); }); } else if (FieldType == typeof(Texture2D) || FieldType == typeof(Texture)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_LOAD_TEXTURE, () => { FileWindow.type = FieldType; UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location => { if (File.Exists(location)) { String path = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, ""); Texture2D texture = Utility.LoadTexture(path, false, false, false); texture.name = path.Replace("\\", "/"); info.SetValue(@object, texture); } else { info.SetValue(@object, Resources.FindObjectsOfTypeAll <Texture>().FirstOrDefault(m => m.name == location)); } }); UIController.Instance.EnableWindow(KittopiaWindows.Files); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(PQSLandControl.LandClass[])) { Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => { UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSLandControl.LandClass[])value, lc => info.SetValue(@object, lc)); UIController.Instance.EnableWindow(KittopiaWindows.LandClass); }); } else if (FieldType == typeof(PQSMod_VertexPlanet.LandClass[])) { Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => { UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_VertexPlanet.LandClass[])value, lc => info.SetValue(@object, lc)); UIController.Instance.EnableWindow(KittopiaWindows.LandClass); }); } else if (FieldType == typeof(PQSMod_HeightColorMap.LandClass[])) { Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => { UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_HeightColorMap.LandClass[])value, lc => info.SetValue(@object, lc)); UIController.Instance.EnableWindow(KittopiaWindows.LandClass); }); } else if (FieldType == typeof(PQSMod_HeightColorMap2.LandClass[])) { Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => { UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_HeightColorMap2.LandClass[])value, lc => info.SetValue(@object, lc)); UIController.Instance.EnableWindow(KittopiaWindows.LandClass); }); } else if (FieldType == typeof(PQSMod_HeightColorMapNoise.LandClass[])) { Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => { UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_HeightColorMapNoise.LandClass[])value, lc => info.SetValue(@object, lc)); UIController.Instance.EnableWindow(KittopiaWindows.LandClass); }); } else if (FieldType == typeof(PQSLandControl.LerpRange)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_LERPRANGE, () => { UIController.Instance.SetEditedObject(KittopiaWindows.LerpRange, (PQSLandControl.LerpRange)value, lc => info.SetValue(@object, lc)); UIController.Instance.EnableWindow(KittopiaWindows.LerpRange); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(PQSMod_VertexPlanet.SimplexWrapper)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_SIMPLEX, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Simplex, (PQSMod_VertexPlanet.SimplexWrapper)value, lc => info.SetValue(@object, lc)); UIController.Instance.EnableWindow(KittopiaWindows.Simplex); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(PQSMod_VertexPlanet.NoiseModWrapper)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_NOISEMOD, () => { UIController.Instance.SetEditedObject(KittopiaWindows.NoiseMod, (PQSMod_VertexPlanet.NoiseModWrapper)value, lc => info.SetValue(@object, lc)); UIController.Instance.EnableWindow(KittopiaWindows.NoiseMod); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(MapSO)) { // Depth if (mapDepth == 5 && value != null) { mapDepth = (Int32)(value as MapSO).Depth; } else if (mapDepth == 5 && value == null) { mapDepth = 0; } // Load the MapSO Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_LOAD_MAPSO, () => { FileWindow.type = FieldType; UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location => { if (File.Exists(location)) { String path = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, ""); Texture2D texture = Utility.LoadTexture(path, false, false, false); texture.name = path.Replace("\\", "/"); MapSO mapSO = ScriptableObject.CreateInstance <MapSO>(); mapSO.CreateMap((MapSO.MapDepth)mapDepth, texture); mapSO.name = path.Replace("\\", "/"); info.SetValue(@object, mapSO); } else { info.SetValue(@object, Resources.FindObjectsOfTypeAll <MapSO>().FirstOrDefault(m => m.name == location)); } }); UIController.Instance.EnableWindow(KittopiaWindows.Files); }, new Rect(200, index * distance + 10, 170, 20)); mapDepth = GUI.SelectionGrid(new Rect(20, index * distance + 10, 350, 20), mapDepth, new [] { "Greyscale", "HeightAlpha", "RGB", "RGBA" }, 4); index++; } else if (FieldType == typeof(PQS)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_SPHERE, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Selector, value as PQS ?? new PQS(), s => info.SetValue(@object, s)); UIController.Instance.EnableWindow(KittopiaWindows.Selector); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(CelestialBody)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_BODY, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Selector, value ?? new CelestialBody(), b => info.SetValue(@object, b)); UIController.Instance.EnableWindow(KittopiaWindows.Selector); }, new Rect(200, index * distance + 10, 170, 20)); } else if (value is Material) // Kopernicus creates Wrappers for the Materials, so key.FieldType == typeof(Material) would return false. :/ { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_MATERIAL, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Material, value as Material, m => info.SetValue(@object, m)); UIController.Instance.EnableWindow(KittopiaWindows.Material); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(FloatCurve)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_CURVE, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Curve, (FloatCurve)value, lc => info.SetValue(@object, lc)); UIController.Instance.EnableWindow(KittopiaWindows.Curve); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(AnimationCurve)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_CURVE, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Curve, new FloatCurve(((AnimationCurve)value).keys), lc => info.SetValue(@object, lc.Curve)); UIController.Instance.EnableWindow(KittopiaWindows.Curve); }, new Rect(200, index * distance + 10, 170, 20)); } else if (FieldType == typeof(Mesh)) { Label(info.Name); index--; Button(Localization.LOC_KITTOPIATECH_EDIT_MESH, () => { FileWindow.type = FieldType; UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location => { if (File.Exists(location)) { String path = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, ""); MeshParser parser = new MeshParser(value as Mesh); parser.SetFromString(path); parser.value.name = path.Replace("\\", "/"); info.SetValue(@object, parser.value); } else { info.SetValue(@object, Resources.FindObjectsOfTypeAll <Mesh>().FirstOrDefault(m => m.name == location)); } }); UIController.Instance.EnableWindow(KittopiaWindows.Files); }, new Rect(200, index * distance + 10, 170, 20)); } } }
//Loads and replaces biomes private void ReplaceBiomes(String set) { if (_debug) { Debug.Log("(CB) Searching for replacement biomes in " + set); } _replaced = true; _biomes = new String[FlightGlobals.Bodies.Count]; int i = 0; char asc = Path.AltDirectorySeparatorChar; char dsc = Path.AltDirectorySeparatorChar; String app = Application.dataPath; //if (_debug) Debug.Log("(CB) App datapath: "+app); app = app.Remove(app.LastIndexOf(dsc) + 1); if (_debug) { Debug.Log("(CB) App: " + app); } if (app.Contains("KSP.app")) { if (_debug) { Debug.Log("(CB) KSP.app detected, attempting OSX fix."); } app = app.Remove(app.LastIndexOf(dsc)); app = app.Remove(app.LastIndexOf(dsc) + 1); if (_debug) { Debug.Log("(CB) App: " + app); } } string path = app + "GameData" + asc + "CustomBiomes" + asc + "PluginData" + asc + "CustomBiomes" + asc + set + asc; if (_debug) { Debug.Log("(CB) Path: " + path); } //String path = Directory.GetCurrentDirectory() + dsc + "GameData" + dsc + "CustomBiomes" + dsc + "PluginData" + dsc + "CustomBiomes" + dsc + set + dsc; foreach (CelestialBody body in FlightGlobals.Bodies) { String name = body.name; /*if (name.Length > 3) * { * if (name.Substring(0,3).Contains("the")) * { * name = name.Remove(0, 4); * if (_debug) Debug.Log("(CB) 'the' removed from "+name); * } * } */ if (_debug) { Debug.Log("(CB) Looking at " + name); } _biomes[i] = name; i++; CBAttributeMapSO biome = body.BiomeMap; //Try loading a texture file try { byte[] bytes; if (_debug) { Debug.Log("(CB) Looking for " + name + ".png..."); } System.IO.FileStream file = new System.IO.FileStream(path + name + ".png", System.IO.FileMode.Open); System.IO.BinaryReader reader = new System.IO.BinaryReader(file); bytes = reader.ReadBytes((int)file.Length); if (_debug) { Debug.Log("(CB) Replacing " + name + "'s biome map."); } Texture2D tex = new Texture2D(1024, 512); tex.LoadImage(bytes); biome.CreateMap(MapSO.MapDepth.RGB, tex); reader.Close(); file.Close(); } catch { //Don't actually care... if (_debug) { Debug.Log("(CB) No map found."); } } //Try loading an attribute file try { if (_debug) { Debug.Log("(CB) Looking for " + name + ".att ..."); } System.IO.FileStream file = new System.IO.FileStream(path + name + ".att", System.IO.FileMode.Open); System.IO.StreamReader reader = new StreamReader(file); if (_debug) { Debug.Log("(CB) Replacing " + name + "'s biome attributes."); } String locale; float a, r, g, b, e; e = float.Parse(reader.ReadLine()); if (e != 0.0) { biome.nonExactThreshold = e; biome.exactSearch = true; } else { biome.exactSearch = false; } CBAttributeMapSO.MapAttribute[] attributes = new CBAttributeMapSO.MapAttribute[0]; while (!reader.EndOfStream) { locale = reader.ReadLine(); CBAttributeMapSO.MapAttribute[] old = new CBAttributeMapSO.MapAttribute[0]; old = attributes; attributes = new CBAttributeMapSO.MapAttribute[old.Length + 1]; old.CopyTo(attributes, 0); a = float.Parse(reader.ReadLine()); if (a > 1) { a = a / 255f; } r = float.Parse(reader.ReadLine()); if (r > 1) { r = r / 255f; } g = float.Parse(reader.ReadLine()); if (g > 1) { g = g / 255f; } b = float.Parse(reader.ReadLine()); if (b > 1) { b = b / 255f; } CBAttributeMapSO.MapAttribute temp = new CBAttributeMapSO.MapAttribute(); temp.name = locale; temp.mapColor = new Color(r, g, b, a); temp.value = a; attributes[attributes.Length - 1] = temp; } biome.Attributes = attributes; //biome.defaultAttribute = attributes[0]; //Seems as good as any reader.Close(); //Close my files file.Close(); } catch { if (_debug) { Debug.Log("(CB) No attributes found."); } } } try //to read the science results { if (_debug) { Debug.Log("(CB) Looking for " + "ScienceResults.txt ..."); } System.IO.FileStream file = new System.IO.FileStream(path + "ScienceResults.txt", System.IO.FileMode.Open); System.IO.StreamReader reader = new StreamReader(file); if (_debug) { Debug.Log("(CB) Parsing Science Results..."); } readResults(reader); } catch { //No science results file. } }
//Draws the tab that displays the list of biomes and attributes for this body private void drawAtributeTab() { int last = _currentBiome; //Check for SOI change if (!FlightGlobals.currentMainBody.name.Equals(_lastMainBody)) { _lastMainBody = FlightGlobals.currentMainBody.name; for (int i = 0; i < _biomes.Length; i++) { if (_biomes[i].Equals(_lastMainBody)) { _currentBiome = i; break; } } } //Load the current biome if (_debug) { Debug.Log("(CB) Loading biome attributes for attributes tab..."); } CBAttributeMapSO biome = LoadBiome(_biomes[_currentBiome]); GUILayout.BeginHorizontal(); //Do the next and prev buttons if (GUILayout.Button("<<", _buttonStyle)) { _currentBiome--; if (_currentBiome < 0) { _currentBiome = _biomes.Length - 1; } //_mainWindow.height = 300; //Reset window height so it resizes correctly for each biome _mapWindow.height = 10; //_mapWindow.width = 2000; if (_debug) { Debug.Log("(CB) Current biome is now " + _biomes[_currentBiome]); } } if (GUILayout.Button(">>", _buttonStyle)) { _currentBiome++; if (_currentBiome >= _biomes.Length) { _currentBiome = 0; } //_mainWindow.height = 300; //Reset window height so it resizes correctly for each biome _mapWindow.height = 10; //_mapWindow.width = 200; if (_debug) { Debug.Log("(CB) Current biome is now " + _biomes[_currentBiome]); } } //If we changed biomes, reset window height, width if (_currentBiome != last) { _mainWindow.height = 10; _mainWindow.width = 10; } GUILayout.EndHorizontal(); if (biome != null) { GUILayout.Label("Biome Attributes for " + _biomes[_currentBiome], _labelStyle); //_mainWindow.height = 100+biome.Attributes.Length * 20; foreach (CBAttributeMapSO.MapAttribute att in biome.Attributes) { if (att != null) { GUILayout.BeginHorizontal(); GUILayout.Label(att.name + " | " + att.value + " | " + att.mapColor.ToString()); Color tmp = GUI.color; GUI.color = att.mapColor; GUILayout.Box(" ", _buttonStyle, GUILayout.Width(20)); GUI.color = tmp; GUILayout.EndHorizontal(); //Debug.Log(att.name); } } if (biome.exactSearch) { GUILayout.Label("Exact Threshold: " + biome.nonExactThreshold); } if (_biomes[_currentBiome].Equals(FlightGlobals.currentMainBody.name)) { double lat, lon; lat = FlightGlobals.ship_latitude; lon = FlightGlobals.ship_longitude; CBAttributeMapSO.MapAttribute ma = FlightGlobals.currentMainBody.BiomeMap.GetAtt(lat * Mathf.Deg2Rad, lon * Mathf.Deg2Rad); GUILayout.Label("Current Biome: " + ma.name, _labelStyle); } } else { GUILayout.Label("Blank biome at " + _biomes[_currentBiome], _labelStyle); } if (GUILayout.Button("Toggle Map", _buttonStyle)) { SaveMe(); _mapMinimized = !_mapMinimized; } }