protected override void Start() { Visible = SCANcontroller.controller.mainMapVisible; v = FlightGlobals.ActiveVessel; data = SCANUtil.getData(v.mainBody); if (data == null) { data = new SCANdata(v.mainBody); SCANcontroller.controller.addToBodyData(v.mainBody, data); } TooltipsEnabled = SCANcontroller.controller.toolTips; }
protected override void DrawWindowPre(int id) { //Keep the map updated with the current vessel location and status v = FlightGlobals.ActiveVessel; data = SCANUtil.getData(v.mainBody); if (data == null) { data = new SCANdata(v.mainBody); SCANcontroller.controller.addToBodyData(v.mainBody, data); } sensors = SCANcontroller.controller.activeSensorsOnVessel(v.id); data.updateImages(sensors); }
internal Texture2D getLegend(int scheme, SCANdata data) { Texture2D t = new Texture2D(256, 1, TextureFormat.RGB24, false); Color[] pix = t.GetPixels(); for (int x = 0; x < 256; ++x) { float val = (x * (data.TerrainConfig.MaxTerrain - data.TerrainConfig.MinTerrain)) / 256f + data.TerrainConfig.MinTerrain; pix[x] = palette.heightToColor(val, scheme, data); } t.SetPixels(pix); t.Apply(); return t; }
internal Texture2D getLegend(float min, float max, int scheme, SCANdata data) { if (legend != null && legendMin == min && legendMax == max && legendScheme == scheme && data.TerrainConfig.ColorPal.hash == dataPalette.hash) return legend; legend = new Texture2D(256, 1, TextureFormat.RGB24, false); legendMin = min; legendMax = max; legendScheme = scheme; dataPalette = data.TerrainConfig.ColorPal; Color[] pix = legend.GetPixels(); for (int x = 0; x < 256; ++x) { float val = (x * (max - min)) / 256f + min; pix[x] = palette.heightToColor(val, scheme, data); } legend.SetPixels(pix); legend.Apply(); return legend; }
/* Calculates the terrain elevation based on scanning coverage; fetches data from elevation cache if possible */ private float terrainElevation(double Lon, double Lat, SCANdata Data, out int Scheme) { float elevation = 0f; Scheme = SCANcontroller.controller.colours; if (SCANUtil.isCovered(Lon, Lat, Data, SCANtype.AltimetryHiRes)) { if (cache) { double lon = fixUnscale(unScaleLongitude(Lon), mapwidth); double lat = fixUnscale(unScaleLatitude(Lat), mapheight); elevation = big_heightmap[Mathf.RoundToInt((float)lon), Mathf.RoundToInt((float)lat)]; if (elevation== 0f) elevation = (float)SCANUtil.getElevation(body, Lon, Lat); } else elevation = (float)SCANUtil.getElevation(body, Lon, Lat); } else { if (cache) { double lon = fixUnscale(unScaleLongitude(Lon), mapwidth); double lat = fixUnscale(unScaleLatitude(Lat), mapheight); elevation = big_heightmap[((int)(lon * 5)) / 5, ((int)(lat * 5)) / 5]; if (elevation == 0f) elevation = (float)SCANUtil.getElevation(body, ((int)(Lon * 5)) / 5, ((int)(Lat * 5)) / 5); } else elevation = (float)SCANUtil.getElevation(body, ((int)(Lon * 5)) / 5, ((int)(Lat * 5)) / 5); Scheme = 1; } return elevation; }
//Debugging option to fill in SCAN maps private void gui_settings_window_mapFill(int id) { growE(); CelestialBody thisBody = null; if (HighLogic.LoadedSceneIsFlight) thisBody = FlightGlobals.currentMainBody; else if (HighLogic.LoadedScene == GameScenes.SPACECENTER) thisBody = Planetarium.fetch.Home; else if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) thisBody = getTargetBody(MapView.MapCamera.target); if (thisBody == null) return; if (GUILayout.Button("Fill SCAN map of " + thisBody.theName)) { SCANdata data = SCANUtil.getData(thisBody); if (data == null) { data = new SCANdata(thisBody); SCANcontroller.controller.addToBodyData(thisBody, data); } data.fillMap(); } if (GUILayout.Button("Fill SCAN map for all planets")) { foreach (CelestialBody b in FlightGlobals.Bodies) { SCANdata data = SCANUtil.getData(b); if (data == null) { data = new SCANdata(b); SCANcontroller.controller.addToBodyData(b, data); } data.fillMap(); } } stopE(); fillS(8); }
/* FIXME: This uses assumed, shared, static constants with Legend stuff in other SCANsat files */ internal static void drawLegend(SCANdata data, SCANmapLegend legend) { GUILayout.Label("", GUILayout.ExpandWidth(true)); Rect r = GUILayoutUtility.GetLastRect(); r.width -= 64; GUI.DrawTexture(r, legend.Legend); //SCANmapLegend.getLegend(data.MinHeight, data.MaxHeight, SCANcontroller.controller.colours, data)); float minLabel = data.TerrainConfig.MinTerrain; float maxLabel = data.TerrainConfig.MaxTerrain; if (data.TerrainConfig.MinTerrain % 1000 != 0) minLabel += 500; if (data.TerrainConfig.MaxTerrain % 1000 != 0) maxLabel -= 500; float range = data.TerrainConfig.MaxTerrain - data.TerrainConfig.MinTerrain; float step = 1000f; if (range > 10000) step = 2000; else if (range < 4000) step = 500; for (float val = minLabel; val < maxLabel; val += step) { drawLegendLabel(r, val, data.TerrainConfig.MinTerrain, data.TerrainConfig.MaxTerrain); } }
private static void drawWaypointLabel(Rect maprect, SCANmap map, SCANwaypoint p, SCANdata data) { double lon = SCANUtil.fixLon(p.Longitude); double lat = SCANUtil.fixLat(p.Latitude); if (map != null) { lat = SCANUtil.fixLat(map.projectLatitude(p.Longitude, p.Latitude)); lon = SCANUtil.fixLon(map.projectLongitude(p.Longitude, p.Latitude)); lat = map.scaleLatitude(lat); lon = map.scaleLongitude(lon); if (lat < 0 || lon < 0 || lat > 180 || lon > 360) return; } lon = lon * maprect.width / 360f; lat = maprect.height - lat * maprect.height / 180f; Rect r = new Rect(maprect.x + (float)lon, maprect.y + (float)lat, 24, 24); r.x -= 12; if (!p.LandingTarget) { r.y -= 24; drawMapIcon(r, SCANskins.SCAN_WaypointIcon, true); } else { r.x += 1; r.y -= 13; drawMapIcon(r, SCANcontroller.controller.mechJebTargetSelection ? SCANskins.SCAN_MechJebIcon : SCANskins.SCAN_TargetIcon, true, SCANcontroller.controller.mechJebTargetSelection ? palette.red : palette.xkcd_PukeGreen, true); } }
//Method to handle active scanner display internal static string InfoText(Vessel v, SCANdata data, bool b) { string infotext = ""; SCANcontroller.SCANsensor s; //Check here for each sensor; if active, in range, and at the ideal altitude s = SCANcontroller.controller.getSensorStatus(v, SCANtype.AltimetryLoRes); if (s == null) infotext += palette.colored(palette.grey, "LO"); else if (!s.inRange) infotext += palette.colored(palette.c_bad, "LO"); else if (!s.bestRange && (Time.realtimeSinceStartup % 2 < 1)) infotext += palette.colored(palette.c_bad, "LO"); else infotext += palette.colored(palette.c_good, "LO"); s = SCANcontroller.controller.getSensorStatus(v, SCANtype.AltimetryHiRes); if (s == null) infotext += palette.colored(palette.grey, " HI"); else if (!s.inRange) infotext += palette.colored(palette.c_bad, " HI"); else if (!s.bestRange && (Time.realtimeSinceStartup % 2 < 1)) infotext += palette.colored(palette.c_bad, " HI"); else infotext += palette.colored(palette.c_good, " HI"); s = SCANcontroller.controller.getSensorStatus(v, SCANtype.Biome); if (s == null) infotext += palette.colored(palette.grey, " MULTI"); else if (!s.inRange) infotext += palette.colored(palette.c_bad, " MULTI"); else if (!s.bestRange && (Time.realtimeSinceStartup % 2 < 1)) infotext += palette.colored(palette.c_bad, " MULTI"); else infotext += palette.colored(palette.c_good, " MULTI"); s = SCANcontroller.controller.getSensorStatus(v, SCANtype.AnomalyDetail); if (s == null) infotext += palette.colored(palette.grey, " BTDT"); else if (!s.inRange) infotext += palette.colored(palette.c_bad, " BTDT"); else if (!s.bestRange && (Time.realtimeSinceStartup % 2 < 1)) infotext += palette.colored(palette.c_bad, " BTDT"); else infotext += palette.colored(palette.c_good, " BTDT"); //Get coverage percentage for all active scanners on the vessel SCANtype active = SCANcontroller.controller.activeSensorsOnVessel(v.id); if (active != SCANtype.Nothing) { double cov = SCANUtil.getCoveragePercentage(data, active); infotext += string.Format(" {0:N1}%", cov); if (b) { infotext = palette.colored(palette.c_bad, "NO POWER"); } } return infotext; }
internal static void mouseOverInfoSimple(double lon, double lat, SCANmap mapObj, SCANdata data, CelestialBody body, bool b) { string info = ""; string posInfo = ""; if (b) { if (SCANUtil.isCovered(lon, lat, data, SCANtype.AltimetryHiRes)) { info += SCANUtil.getElevation(body, lon, lat).ToString("N0") + "m "; } else if (SCANUtil.isCovered(lon, lat, data, SCANtype.AltimetryLoRes)) { info += (((int)SCANUtil.getElevation(body, lon, lat) / 500) * 500).ToString() + "m "; } if (SCANUtil.isCovered(lon, lat, data, SCANtype.Biome)) { info += SCANUtil.getBiomeName(body, lon, lat) + " "; } if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && mapObj.Resource != null) //Adds selected resource amount to big map legend { if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) { double amount = SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body); string label; if (amount < 0) label = "Unknown"; else { if (amount > 1) amount = 1; label = amount.ToString("P2"); } info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); } } if (SCANcontroller.controller.map_waypoints && WaypointManager.Instance() != null) { double range = ContractDefs.Survey.MaximumTriggerRange; foreach (SCANwaypoint p in data.Waypoints) { if (!p.LandingTarget) { if (p.Root != null) { if (p.Root.ContractState != Contracts.Contract.State.Active) continue; } if (p.Param != null) { if (p.Param.State != Contracts.ParameterState.Incomplete) continue; } if (WaypointManager.Instance().Distance(lat, lon, 1000, p.Latitude, p.Longitude, 1000, body) <= range) { info += p.Name + " "; break; } } } } posInfo += string.Format("{0} ({1:F2}°,{2:F2}°)", toDMS(lat, lon), lat, lon); } //Draw the readout info labels readableLabel(info, false); SCAN_MBW.fillS(-10); readableLabel(posInfo, false); }
/* 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(); }
protected override void DrawWindowPre(int id) { //Some clumsy logic is used here to ensure that the color selection fields always remain in sync with the current map in each scene if (HighLogic.LoadedSceneIsFlight) { if (data == null) { data = SCANUtil.getData(FlightGlobals.currentMainBody); if (data == null) { data = new SCANdata(FlightGlobals.currentMainBody); SCANcontroller.controller.addToBodyData(FlightGlobals.currentMainBody, data); } } if (bigMapObj.Visible && SCANBigMap.BigMap != null) { data = bigMapObj.Data; bigMap = SCANBigMap.BigMap; } else if (data.Body != FlightGlobals.currentMainBody) { data = SCANUtil.getData(FlightGlobals.currentMainBody); if (data == null) { data = new SCANdata(FlightGlobals.currentMainBody); SCANcontroller.controller.addToBodyData(FlightGlobals.currentMainBody, data); } } if (bigMap == null) { if (SCANBigMap.BigMap != null) { bigMap = SCANBigMap.BigMap; } } } //Lock space center click through - Sync SCANdata else if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { 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); } } if (kscMapObj.Visible) { data = kscMapObj.Data; bigMap = SCANkscMap.BigMap; } else if (data.Body != Planetarium.fetch.Home) { data = SCANUtil.getData(Planetarium.fetch.Home); if (data == null) { data = new SCANdata(Planetarium.fetch.Home); SCANcontroller.controller.addToBodyData(Planetarium.fetch.Home, data); } } if (bigMap == null) { if (SCANkscMap.BigMap != null) { bigMap = SCANkscMap.BigMap; } } Vector2 mousePos = Input.mousePosition; mousePos.y = Screen.height - mousePos.y; if (WindowRect.Contains(mousePos) && !controlLock) { InputLockManager.SetControlLock(ControlTypes.CAMERACONTROLS | ControlTypes.KSC_ALL, lockID); controlLock = true; } else if (!WindowRect.Contains(mousePos) && controlLock) { removeControlLocks(); } } //Lock tracking scene click through - Sync SCANdata else if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) { 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); } } if (kscMapObj.Visible) { data = kscMapObj.Data; bigMap = SCANkscMap.BigMap; } else if (data.Body != Planetarium.fetch.Home) { data = SCANUtil.getData(Planetarium.fetch.Home); if (data == null) { data = new SCANdata(Planetarium.fetch.Home); SCANcontroller.controller.addToBodyData(Planetarium.fetch.Home, data); } } if (bigMap == null) { if (SCANkscMap.BigMap != null) { bigMap = SCANkscMap.BigMap; } } Vector2 mousePos = Input.mousePosition; mousePos.y = Screen.height - mousePos.y; if (WindowRect.Contains(mousePos) && !controlLock) { InputLockManager.SetControlLock(ControlTypes.TRACKINGSTATION_UI, lockID); controlLock = true; } else if (!WindowRect.Contains(mousePos) && controlLock) { removeControlLocks(); } } //This updates all of the fields whenever the palette selection is changed if (windowMode == 0 && (currentLegend == null || bodyIndex != data.Body.flightGlobalsIndex)) { currentTerrain = new SCANterrainConfig(data.TerrainConfig); SCANUtil.SCANdebugLog("Trigger Body Change"); bodyIndex = data.Body.flightGlobalsIndex; currentTerrain = new SCANterrainConfig(data.TerrainConfig); updateUI(); } if (windowMode == 0 && previewLegend == null) { drawPreviewLegend(); } if (!dropDown) { paletteBox = false; resourceBox = false; saveWarning = false; } }
//Handles various map labels; probably should be split up into multiple methods internal static void drawMapLabels(Rect maprect, Vessel vessel, SCANmap map, SCANdata data, CelestialBody body, bool showAnom, bool showWaypoints) { //This section handles flag and asteroid labels foreach (Vessel v in FlightGlobals.Vessels) { if (v.mainBody == body) { if (MapView.OrbitIconsMap != null) { if (v.vesselType == VesselType.Flag && SCANcontroller.controller.map_flags) { drawVesselLabel(maprect, map, 0, v); } if (v.vesselType == VesselType.SpaceObject && SCANcontroller.controller.map_asteroids) { drawVesselLabel(maprect, map, 0, v); } } } } //This section handles anomaly labels if (showAnom) { foreach (SCANanomaly anomaly in data.Anomalies) { drawAnomalyLabel(maprect, map, anomaly); } } if (showWaypoints) { foreach (SCANwaypoint p in data.Waypoints) { if (!p.LandingTarget) { if (p.Root != null) { if (p.Root.ContractState != Contracts.Contract.State.Active) continue; } if (p.Param != null) { if (p.Param.State != Contracts.ParameterState.Incomplete) continue; } } drawWaypointLabel(maprect, map, p, data); } } if (vessel != null) { if (vessel.mainBody == body) drawVesselLabel(maprect, map, 0, vessel); } }
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); }
public static Color heightToColor(float val, int scheme, SCANdata data) { Color32[] c = data.TerrainConfig.ColorPal.colors; if (data.TerrainConfig.PalRev) c = data.TerrainConfig.ColorPal.colorsReverse; if (scheme == 0) return heightToColor(val, data.TerrainConfig.MaxTerrain, data.TerrainConfig.MinTerrain, data.TerrainConfig.ClampTerrain, data.TerrainConfig.PalDis, c); else return heightToColor(val, data.TerrainConfig.MaxTerrain, data.TerrainConfig.MinTerrain, data.TerrainConfig.PalDis); }