private Dictionary<string, SCANresourceBody> copyBodyConfigs(SCANresourceGlobal c) { Dictionary<string, SCANresourceBody> newCopy = new Dictionary<string, SCANresourceBody>(); foreach (SCANresourceBody r in c.masterBodyConfigs.Values) { SCANresourceBody newR = new SCANresourceBody(r); if (!newCopy.ContainsKey(newR.BodyName)) newCopy.Add(newR.BodyName, newR); } return newCopy; }
private Dictionary <string, SCANresourceBody> copyBodyConfigs(SCANresourceGlobal c) { Dictionary <string, SCANresourceBody> newCopy = new Dictionary <string, SCANresourceBody>(); foreach (SCANresourceBody r in c.masterBodyConfigs.Values) { SCANresourceBody newR = new SCANresourceBody(r); if (!newCopy.ContainsKey(newR.BodyName)) { newCopy.Add(newR.BodyName, newR); } } return(newCopy); }
internal SCANresourceGlobal(SCANresourceGlobal copy) { name = copy.name; resourceTransparency = copy.resourceTransparency; lowResourceColor = copy.lowResourceColor; highResourceColor = copy.highResourceColor; sType = copy.sType; resourceType = copy.resourceType; masterBodyConfigs = copyBodyConfigs(copy); defaultLowColor = copy.defaultLowColor; defaultHighColor = copy.defaultHighColor; defaultTrans = copy.defaultTrans; defaultMinValue = copy.defaultMinValue; defaultMaxValue = copy.defaultMaxValue; }
protected override void Start() { if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION) { kscMapObj = (SCANkscMap)SCANcontroller.controller.kscMap; if (SCANkscMap.BigMap != null) bigMap = SCANkscMap.BigMap; if (kscMapObj.Data != null) data = kscMapObj.Data; } else if (HighLogic.LoadedSceneIsFlight) { bigMapObj = (SCANBigMap)SCANcontroller.controller.BigMap; if (SCANBigMap.BigMap != null) bigMap = SCANBigMap.BigMap; if (bigMapObj.Data != null) data = bigMapObj.Data; } if (data == null) { data = SCANUtil.getData(Planetarium.fetch.Home); if (data == null) { data = new SCANdata(Planetarium.fetch.Home); SCANcontroller.controller.addToBodyData(Planetarium.fetch.Home, data); } } currentTerrain = new SCANterrainConfig(data.TerrainConfig); stockBiomes = SCANcontroller.controller.useStockBiomes; minTerrainSlider = new SCANuiSlider(data.TerrainConfig.DefaultMinHeight - SCANconfigLoader.SCANNode.RangeBelowMinHeight, data.TerrainConfig.MaxTerrain - 100, data.TerrainConfig.MinTerrain, "Min: ", "m", -2); maxTerrainSlider = new SCANuiSlider(data.TerrainConfig.MinTerrain + 100, data.TerrainConfig.DefaultMaxHeight + SCANconfigLoader.SCANNode.RangeAboveMaxHeight, data.TerrainConfig.MaxTerrain, "Max: ", "m", -2); clampTerrainSlider = new SCANuiSlider(data.TerrainConfig.MinTerrain + 10, data.TerrainConfig.MaxTerrain - 10, data.TerrainConfig.ClampTerrain ?? data.TerrainConfig.MinTerrain + 10, "Clamp: ", "m", -1); paletteSizeSlider = new SCANuiSlider(3, 12, data.TerrainConfig.PalSize, "Palette Size: ", "", 0); slopeColorPickerLow = new SCANuiColorPicker(SCANcontroller.controller.lowSlopeColorOne, SCANcontroller.controller.highSlopeColorOne, true); slopeColorPickerHigh = new SCANuiColorPicker(SCANcontroller.controller.lowSlopeColorTwo, SCANcontroller.controller.highSlopeColorTwo, true); slopeColorPickerLow.updateOldSwatches(); slopeColorPickerHigh.updateOldSwatches(); bTrans = SCANcontroller.controller.biomeTransparency; biomeTransSlider = new SCANuiSlider(0, 80, bTrans, "Ter. Trans: ", "%", 0); biomeColorPicker = new SCANuiColorPicker(SCANcontroller.controller.lowBiomeColor, SCANcontroller.controller.highBiomeColor, true); biomeColorPicker.updateOldSwatches(); if (SCANconfigLoader.GlobalResource) { loadedResources = SCANcontroller.setLoadedResourceList(); currentResource = new SCANresourceGlobal(loadedResources[0]); currentResource.CurrentBodyConfig(data.Body.name); if (currentResource != null) { resourceMinSlider = new SCANuiSlider(0, currentResource.CurrentBody.MinValue - 0.1f, currentResource.CurrentBody.MinValue, "Min: ", "%", 1); resourceMaxSlider = new SCANuiSlider(currentResource.CurrentBody.MinValue + 0.1f, 100, currentResource.CurrentBody.MaxValue, "Max: ", "%", 1); resourceTransSlider = new SCANuiSlider(0, 80, currentResource.Transparency, "Trans: ", "%", 0); resourceColorPicker = new SCANuiColorPicker(currentResource.MinColor, currentResource.MaxColor, true); } } bodyIndex = data.Body.flightGlobalsIndex; if (windowMode > 3 || (windowMode > 2 && !SCANconfigLoader.GlobalResource)) windowMode = 0; setSizeSlider(currentTerrain.ColorPal.kind); }
//Drop down menu for palette selection private void dropDownBox(int id) { if (dropDown) { if (paletteBox && windowMode == 0) { ddRect = new Rect(40, 120, 100, 100); GUI.Box(ddRect, ""); for (int i = 0; i < Palette.kindNames.Length; i++) { Rect r = new Rect(ddRect.x + 10, ddRect.y + 5 + (i * 23), 80, 22); if (GUI.Button(r, Palette.kindNames[i], SCANskins.SCAN_dropDownButton)) { paletteBox = false; palette.CurrentPalettes = palette.setCurrentPalettesType((Palette.Kind)i, (int)pSize); setSizeSlider((Palette.Kind)i); } } } else if (resourceBox && windowMode == 3) { ddRect = new Rect(WindowRect.width - 440, 115, 160, 140); GUI.Box(ddRect, ""); for (int i = 0; i < loadedResources.Count; i ++) { scrollR = GUI.BeginScrollView(ddRect, scrollR, new Rect(0, 0, 140, 23 * loadedResources.Count)); Rect r = new Rect(2, i * 23, 136, 22); if (GUI.Button(r, loadedResources[i].Name, SCANskins.SCAN_dropDownButton)) { currentResource = new SCANresourceGlobal(loadedResources[i]); currentResource.CurrentBodyConfig(data.Body.name); fineControlMode = oldFineControl = false; updateUI(); dropDown = false; resourceBox = false; } GUI.EndScrollView(); } } else if (saveWarning) { ddRect = new Rect(WindowRect.width - 182, WindowRect.height - 92, 180, 90); GUI.Box(ddRect, ""); Rect r = new Rect(ddRect.x + 10, ddRect.y, 160, 60); GUI.Label(r, "Overwrite Existing Config File?", SCANskins.SCAN_headlineSmall); r.x += 40; r.y += 55; r.width = 80; r.height = 30; if (GUI.Button(r, "Confirm", SCANskins.SCAN_buttonWarning)) { dropDown = false; saveWarning = false; SCANconfigLoader.SCANNode.Save(); } } else dropDown = false; } }
public void resetMap(bool setRes = true) { mapstep = 0; if (SCANconfigLoader.GlobalResource && setRes) { //Make sure that a resource is initialized if necessary if (resource == null && body != null) { resource = SCANcontroller.getResourceNode(SCANcontroller.controller.resourceSelection); if (resource == null) resource = SCANcontroller.GetFirstResource; resource.CurrentBodyConfig(body.name); } } }
private double[] mapline; // all refs are below /* MAP: nearly trivial functions */ public void setBody(CelestialBody b) { if (body == b) return; body = b; if (SCANconfigLoader.GlobalResource) { resource = SCANcontroller.getResourceNode(SCANcontroller.controller.resourceSelection); if (resource == null) resource = SCANcontroller.GetFirstResource; resource.CurrentBodyConfig(body.name); } }
/* Converts resource amount to pixel color */ internal static Color resourceToColor(double Lon, double Lat, SCANdata Data, Color BaseColor, SCANresourceGlobal Resource, float Transparency = 0.4f) { double amount = resourceMapValue(Lon, Lat, Data, Resource); if (amount < 0) return BaseColor; else if (amount == 0) return palette.lerp(BaseColor, palette.grey, Transparency); else return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, (float)amount / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); }
private static double resourceMapValue(double Lon, double Lat, SCANdata Data, SCANresourceGlobal resource) { double amount = 0; if (SCANUtil.isCovered(Lon, Lat, Data, resource.SType)) { amount = SCANUtil.ResourceOverlay(Lat, Lon, resource.Name, Data.Body); amount *= 100; if (amount >= resource.CurrentBody.MinValue) { if (amount > resource.CurrentBody.MaxValue) amount = resource.CurrentBody.MaxValue; } else amount = 0; } else amount = -1; return amount; }
internal static void drawResourceTexture(int height, ref int step, SCANdata data, SCANresourceGlobal resource) { Color[] pix; float scale = height / 180f; if (resource.MapOverlay == null) { resource.MapOverlay = new Texture2D(height * 2, height, TextureFormat.ARGB32, true); pix = resource.MapOverlay.GetPixels(); for (int i = 0; i < pix.Length; i++) pix[i] = palette.clear; resource.MapOverlay.SetPixels(pix); } else if (step >= resource.MapOverlay.height) { return; } pix = resource.MapOverlay.GetPixels(0, step, resource.MapOverlay.width, 1); for (int i = 0; i < pix.Length; i++) { double lon = (i / scale); double lat = (step / scale) - 90; if (lon <= 180) lon = 180 - lon; else lon = (lon - 180) * -1; lon -= 90; if (lon < -180) lon += 360; pix[i] = resourceToColor(lon, lat, data, palette.clear, resource, 0.05f); } resource.MapOverlay.SetPixels(0, step, resource.MapOverlay.width, 1, pix); step++; if (step % 10 == 0 || step >= height) resource.MapOverlay.Apply(); }
public static void addToResourceData (string name, SCANresourceGlobal res) { if (!masterResourceNodes.ContainsKey(name)) { masterResourceNodes.Add(name, res); } else Debug.LogError(string.Format("[SCANsat] Warning: SCANResource Dictionary Already Contains Key of This Type: Resource: {0}", name)); }
public static void updateSCANresource (SCANresourceGlobal r, bool all) { SCANresourceGlobal update = getResourceNode(r.Name); if (update != null) { update.MinColor = r.MinColor; update.MaxColor = r.MaxColor; update.Transparency = r.Transparency; if (all) { for (int i = 0; i < update.getBodyCount; i++) { SCANresourceBody b = update.getBodyConfig(i); if (b != null) { SCANresourceBody bNew = r.getBodyConfig(b.BodyName); if (bNew != null) { b.MinValue = bNew.MinValue; b.MaxValue = bNew.MaxValue; } } } } else { SCANresourceBody b = update.getBodyConfig(r.CurrentBody.BodyName); if (b != null) { b.MinValue = r.CurrentBody.MinValue; b.MaxValue = r.CurrentBody.MaxValue; } } } }
private string saveResources(SCANresourceGlobal resource) { List<string> sL = new List<string>(); for (int j = 0; j < resource.getBodyCount; j++) { SCANresourceBody bodyRes = resource.getBodyConfig(j); if (bodyRes != null) { string a = string.Format("{0}|{1:F3}|{2:F3}", bodyRes.Index, bodyRes.MinValue, bodyRes.MaxValue); sL.Add(a); } } return string.Join(",", sL.ToArray()); }