Exemple #1
0
        //Pulls data out of the Kethane database to update the SCANsat resource coverage map - intentionally slow
        private void rebuildResourceArray()
        {
            SCANdata data = SCANUtil.getData(body);

            if (!rebuildingArray)
            {
                print("[SCAN Kethane] Rebuilding SCANsat Kethane Array");
                rebuildingArray = true;
            }
            for (int ilon = 0; ilon < 360; ilon++)              //Run 360 points per frame; 3 seconds at 60FPS
            {
                cell = getKethaneCell(ilon - 180, rebuildStep - 90);
                if (KethaneData.Current[resource.name][body].IsCellScanned(cell))
                {
                    updateResourceArray(ilon, rebuildStep, resource.type, data);
                    double?depositValue = KethaneData.Current[resource.name][body].Resources.GetQuantity(cell);
                    if (depositValue != null)
                    {
                        updateResourceValue(ilon, rebuildStep, depositValue, data);
                    }
                    else
                    {
                        updateResourceValue(ilon, rebuildStep, -1d, data);                         //Give empty cells -1 resources, account for this later on
                    }
                }
            }
            rebuildStep++;
            if (rebuildStep >= 180)
            {
                SCANcontroller.controller.kethaneBusy = false;
                rebuildingArray = false;
                print("[SCAN Kethane] SCANsat Kethane Array Rebuilt");
            }
        }
Exemple #2
0
 protected override void Start()
 {
     Visible = SCANcontroller.controller.kscMapVisible;
     if (b == null)
     {
         b = Planetarium.fetch.Home;
     }
     if (bigmap == null)
     {
         bigmap = new SCANmap(b, true);
         bigmap.setProjection((MapProjection)SCANcontroller.controller.projection);
         bigmap.setWidth(720);
     }
     currentColor  = SCANcontroller.controller.colours == 0;
     lastColor     = currentColor;
     lastResource  = SCANcontroller.controller.map_ResourceOverlay;
     WindowCaption = string.Format("Map of {0}", b.theName);
     data          = SCANUtil.getData(b);
     if (data == null)
     {
         data = new SCANdata(b);
         SCANcontroller.controller.addToBodyData(b, data);
     }
     bigmap.setBody(b);
     if (SCANconfigLoader.GlobalResource)
     {
         loadedResources = SCANcontroller.setLoadedResourceList();
     }
     TooltipsEnabled = SCANcontroller.controller.toolTips;
 }
 private void soiChange(GameEvents.HostedFromToAction <Vessel, CelestialBody> VC)
 {
     data = SCANUtil.getData(VC.to);
     if (data == null)
     {
         data = new SCANdata(VC.to);
         SCANcontroller.controller.addToBodyData(VC.to, data);
     }
     planetConstants(VC.to);
 }
 protected override void Start()
 {
     GameEvents.onVesselSOIChanged.Add(soiChange);
     data = SCANUtil.getData(FlightGlobals.currentMainBody);
     if (data == null)
     {
         data = new SCANdata(FlightGlobals.currentMainBody);
         SCANcontroller.controller.addToBodyData(FlightGlobals.currentMainBody, data);
     }
     planetConstants(FlightGlobals.currentMainBody);
 }
Exemple #5
0
 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;
 }
Exemple #6
0
 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);
 }
Exemple #7
0
        private void setResource(string s)           //Watcher to check for the user switching to different Kethane resources
        {
            if (s == resource.name)
            {
                return;
            }
            resource = SCANcontroller.ResourcesList[SCANcontroller.controller.gridSelection];
            reset    = SCANcontroller.controller.kethaneReset;
            SCANcontroller.controller.map_ResourceOverlay = false;             //Force the overlay off to allow array to rebuild
            SCANdata data = SCANUtil.getData(body);

            data.kethaneValueMap = new float[360, 180];
            rebuildStep          = 0;
            SCANcontroller.controller.kethaneBusy = true;
        }
        public void setMapCenter(double lat, double lon, SCANmap big)
        {
            Visible = true;
            bigmap  = big;

            SCANcontroller.controller.TargetSelecting       = false;
            SCANcontroller.controller.TargetSelectingActive = false;

            if (bigmap.Projection == MapProjection.Polar)
            {
                spotmap.setProjection(MapProjection.Polar);
            }
            else
            {
                spotmap.setProjection(MapProjection.Rectangular);
            }

            if (bigmap.Body != b)
            {
                SCANdata dat = SCANUtil.getData(bigmap.Body);
                if (dat == null)
                {
                    dat = new SCANdata(bigmap.Body);
                }

                data = dat;
                b    = data.Body;

                spotmap.setBody(b);
            }

            if (SCANconfigLoader.GlobalResource && narrowBand)
            {
                spotmap.Resource = bigmap.Resource;
                spotmap.Resource.CurrentBodyConfig(b.name);
            }

            spotmap.MapScale = 10;

            spotmap.centerAround(lon, lat);
            if (SCANcontroller.controller.needsNarrowBand && SCANcontroller.controller.map_ResourceOverlay)
            {
                checkForScanners();
            }
            spotmap.resetMap(bigmap.MType, false, narrowBand);
        }
Exemple #9
0
 private void setBody(CelestialBody b)           //Watcher to check for Celestial Body changes
 {
     if (body == b)
     {
         return;
     }
     if (b != null)
     {
         body     = b;
         resource = SCANcontroller.ResourcesList[SCANcontroller.controller.gridSelection];
         reset    = SCANcontroller.controller.kethaneReset;
         SCANcontroller.controller.map_ResourceOverlay = false;                 //Force the overlay off to allow array to rebuild
         SCANdata data = SCANUtil.getData(body);
         data.kethaneValueMap = new float[360, 180];
         rebuildStep          = 0;
         SCANcontroller.controller.kethaneBusy = true;
     }
 }
Exemple #10
0
        public ListValue GetAnomalies(BodyTarget body)
        {
            ListValue anomalies = new ListValue();

            if (IsModInstalled("scansat"))
            {
                var scanData = SCANUtil.getData(body.Body);

                if (scanData != null)
                {
                    foreach (var anomaly in scanData.Anomalies)
                    {
                        if (anomaly.Known)
                        {
                            anomalies.Add(new AnomalyValue(anomaly, body.Body, shared));
                        }
                    }
                }
            }

            return(anomalies);
        }
        private void RedrawMap()
        {
            map = new SCANmap();
            map.setProjection(MapProjection.Rectangular);
            orbitingBody = vessel.mainBody;
            map.setBody(vessel.mainBody);
            map.setSize(screenWidth, screenHeight);
            map.MapScale *= (zoomLevel * zoomLevel + zoomModifier);
            mapCenterLong = vessel.longitude;
            mapCenterLat  = vessel.latitude;
            // That's really just sweeping the problem under the carpet instead of fixing it, but meh.
            if (zoomLevel == 0)
            {
                mapCenterLat = 0;
            }
            map.centerAround(mapCenterLong, mapCenterLat);
            map.resetMap((mapType)mapMode, false);

            // Compute and store the map scale factors in mapSizeScale.  We
            // use these values for every segment when drawing trails, so it
            // makes sense to compute it only when it changes.
            mapSizeScale    = new Vector2d(360.0 * map.MapScale / map.MapWidth, 180.0 * map.MapScale / map.MapHeight);
            redrawDeviation = redrawEdge * 180 / (zoomLevel * zoomLevel + zoomModifier);
            try {
                SCANdata data = SCANUtil.getData(vessel.mainBody);
                if (data != null)
                {
                    localAnomalies = data.Anomalies;
                    localWaypoints = data.Waypoints;
                }
            } catch {
                Debug.Log("JSISCANsatRPM: Could not get a list of anomalies, what happened?");
            }
            // MATH!
            double kmPerDegreeLon  = (2 * Math.PI * (orbitingBody.Radius / 1000d)) / 360d;
            double pixelsPerDegree = Math.Abs(longitudeToPixels(mapCenterLong + (((mapCenterLong + 1) > 360) ? -1 : 1), mapCenterLat) - longitudeToPixels(mapCenterLong, mapCenterLat));

            pixelsPerKm = pixelsPerDegree / kmPerDegreeLon;
        }
Exemple #12
0
        //Reset the resource value array - quicker than rebuildKethaneData (), called on map resets
        private void rebuildResourceValue(SCANdata.SCANtype type)
        {
            if (!rebuildingValue)
            {
                print("[SCAN Kethane] Rebuilding Value Array");
                rebuildingValue = true;
            }
            SCANdata data = SCANUtil.getData(body);

            for (int ilat = 4 * rebuildValueStep; ilat < 4 * (rebuildValueStep + 1); ilat++)
            {
                for (int ilon = 0; ilon < 360; ilon++)
                {
                    if (SCANUtil.isCovered(ilon, ilat, body, (int)type))
                    {
                        if (data.kethaneValueMap[ilon, ilat] == 0)                           //Only check unassigned values
                        {
                            cell = getKethaneCell(ilon - 180, ilat - 90);
                            double?depositValue = KethaneData.Current[resource.name][body].Resources.GetQuantity(cell);
                            if (depositValue != null)
                            {
                                updateResourceValue(ilon, ilat, depositValue, data);
                            }
                            else
                            {
                                updateResourceValue(ilon, ilat, -1d, data);                                  //Give empty cells -1 resources, account for this later on
                            }
                        }
                    }
                }
            }
            rebuildValueStep++;
            if (rebuildValueStep >= 45)
            {
                print("[SCAN Kethane] Value Array Rebuilt");
                rebuildingValue = false;
            }
        }
 protected override void Start()
 {
     //Initialize the map object
     Visible = SCANcontroller.controller.bigMapVisible;
     if (v == null)
     {
         v = FlightGlobals.ActiveVessel;
     }
     if (b == null)
     {
         b = v.mainBody;
     }
     if (bigmap == null)
     {
         bigmap = new SCANmap(b, true);
         bigmap.setProjection((MapProjection)SCANcontroller.controller.projection);
         bigmap.setWidth(SCANcontroller.controller.map_width);
     }
     WindowRect.x  = SCANcontroller.controller.map_x;
     WindowRect.y  = SCANcontroller.controller.map_y;
     currentColor  = SCANcontroller.controller.colours == 0;
     lastColor     = currentColor;
     lastResource  = SCANcontroller.controller.map_ResourceOverlay;
     WindowCaption = string.Format("Map of {0}", b.theName);
     data          = SCANUtil.getData(b);
     if (data == null)
     {
         data = new SCANdata(b);
         SCANcontroller.controller.addToBodyData(b, data);
     }
     bigmap.setBody(b);
     if (SCANconfigLoader.GlobalResource)
     {
         loadedResources = SCANcontroller.setLoadedResourceList();
     }
     TooltipsEnabled = SCANcontroller.controller.toolTips;
 }
Exemple #14
0
        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;
            }
        }
Exemple #15
0
        /* MAP: build: map to Texture2D */
        internal Texture2D getPartialMap()
        {
            SCANdata data = SCANUtil.getData(body);

            if (data == null)
            {
                return(new Texture2D(1, 1));
            }
            Color[] pix;

            /* init cache if necessary */
            if (cache)
            {
                if (body != big_heightmap_body)
                {
                    for (int x = 0; x < mapwidth; x++)
                    {
                        for (int y = 0; y < mapwidth / 2; y++)
                        {
                            big_heightmap[x, y] = 0f;
                        }
                    }
                    big_heightmap_body = body;
                }
            }

            if (map == null)
            {
                map = new Texture2D(mapwidth, mapheight, TextureFormat.ARGB32, false);
                pix = map.GetPixels();
                for (int i = 0; i < pix.Length; ++i)
                {
                    pix[i] = palette.clear;
                }
                map.SetPixels(pix);
            }
            else if (mapstep >= map.height)
            {
                return(map);
            }

            if (palette.redline == null || palette.redline.Length != map.width)
            {
                palette.redline = new Color[map.width];
                for (int i = 0; i < palette.redline.Length; ++i)
                {
                    palette.redline[i] = palette.red;
                }
            }

            if (mapstep < map.height - 1)
            {
                map.SetPixels(0, mapstep + 1, map.width, 1, palette.redline);
            }

            if (mapstep <= 0)
            {
                mapstep = 0;
                mapline = new double[map.width];
            }

            pix = map.GetPixels(0, mapstep, map.width, 1);

            for (int i = 0; i < map.width; i++)
            {
                Color baseColor = palette.grey;
                pix[i] = baseColor;
                int    scheme = SCANcontroller.controller.colours;
                float  projVal = 0f;
                double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset;
                double lon = (i * 1.0f / mapscale) - 180f + lon_offset;
                double la = lat, lo = lon;
                lat = unprojectLatitude(lo, la);
                lon = unprojectLongitude(lo, la);

                /* Introduce altimetry check here; Use unprojected lat/long coordinates
                 * All cached altimetry data stored in a single 2D array in rectangular format
                 * Pull altimetry data from cache after unprojection
                 */

                if (body.pqsController != null && cache)
                {
                    if (big_heightmap[i, mapstep] == 0f)
                    {
                        if (SCANUtil.isCovered(lo, la, data, SCANtype.Altimetry))
                        {
                            terrainHeightToArray(lo, la, i, mapstep);
                        }
                    }
                }

                if (double.IsNaN(lat) || double.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180)
                {
                    pix[i] = palette.clear;
                    continue;
                }

                /* Altimetry Map */
                if (mType == mapType.Altimetry)
                {
                    if (body.pqsController == null)
                    {
                        baseColor = palette.lerp(palette.black, palette.white, UnityEngine.Random.value);
                    }
                    else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Altimetry))
                    {
                        projVal   = terrainElevation(lon, lat, data, out scheme);
                        baseColor = palette.heightToColor(projVal, scheme, data);
                    }
                    mapline[i] = projVal;

                    if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null)
                    {
                        pix[i] = SCANuiUtil.resourceToColor(lon, lat, data, baseColor, resource);
                    }
                    else
                    {
                        pix[i] = baseColor;
                    }

                    /* draw height lines - works, but mostly useless...
                     * int step = (int)(val / 1000);
                     * int step_h = step, step_v = step;
                     * if(i > 0) step_h = (int)(bigline[i - 1] / 1000);
                     * if(bigstep > 0) step_v = (int)(bigline[i] / 1000);
                     * if(step != step_h || step != step_v) {
                     * pix[i] = palette.white;
                     * }
                     */
                    //mapline [i] = val;
                }

                /* Slope Map */
                else if (mType == mapType.Slope)
                {
                    if (body.pqsController == null)
                    {
                        baseColor = palette.lerp(palette.black, palette.white, UnityEngine.Random.value);
                    }
                    else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Altimetry))
                    {
                        projVal = terrainElevation(lon, lat, data, out scheme);
                        if (mapstep == 0)
                        {
                            baseColor = palette.grey;
                        }
                        else
                        {
                            // This doesn't actually calculate the slope per se, but it's faster
                            // than asking for yet more elevation data. Please don't use this
                            // code to operate nuclear power plants or rockets.
                            double v1 = mapline[i];
                            if (i > 0)
                            {
                                v1 = Math.Max(v1, mapline[i - 1]);
                            }
                            if (i < mapline.Length - 1)
                            {
                                v1 = Math.Max(v1, mapline[i + 1]);
                            }
                            float v = Mathf.Clamp((float)Math.Abs(projVal - v1) / 1000f, 0, 2f);
                            if (SCANcontroller.controller.colours == 1)
                            {
                                baseColor = palette.lerp(palette.black, palette.white, v / 2f);
                            }
                            else
                            {
                                if (v < 1)
                                {
                                    baseColor = palette.lerp(SCANcontroller.controller.lowSlopeColorOne, SCANcontroller.controller.highSlopeColorOne, v);
                                }
                                else
                                {
                                    baseColor = palette.lerp(SCANcontroller.controller.lowSlopeColorTwo, SCANcontroller.controller.highSlopeColorTwo, v - 1);
                                }
                            }
                        }
                        mapline[i] = projVal;
                    }
                    if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null)
                    {
                        pix[i] = SCANuiUtil.resourceToColor(lon, lat, data, baseColor, resource);
                    }
                    else
                    {
                        pix[i] = baseColor;
                    }
                }

                /* Biome Map */
                else if (mType == mapType.Biome)
                {
                    if (body.BiomeMap == null)
                    {
                        baseColor = palette.lerp(palette.black, palette.white, UnityEngine.Random.value);
                    }

                    /* // this just basically stretches the actual biome map to fit... it looks horrible
                     * float u = ((lon + 360 + 180 + 90)) % 360;
                     * float v = ((lat + 180 + 90)) % 180;
                     * if(u < 0 || v < 0 || u >= 360 || v >= 180) continue;
                     * u /= 360f; v /= 180f;
                     * pix[i] = body.BiomeMap.Map.GetPixelBilinear(u, v);
                     */
                    else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Biome))
                    {
                        double bio   = SCANUtil.getBiomeIndexFraction(body, lon, lat);
                        Color  biome = palette.grey;
                        if (SCANcontroller.controller.colours == 1)
                        {
                            if ((i > 0 && mapline[i - 1] != bio) || (mapstep > 0 && mapline[i] != bio))
                            {
                                biome = palette.white;
                            }
                            else
                            {
                                biome = palette.lerp(palette.black, palette.white, (float)bio);
                            }
                        }
                        else
                        {
                            Color elevation = palette.grey;
                            if (SCANcontroller.controller.biomeTransparency > 0)
                            {
                                if (body.pqsController == null)
                                {
                                    elevation = palette.grey;
                                }
                                else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Altimetry))
                                {
                                    projVal   = terrainElevation(lon, lat, data, out scheme);
                                    elevation = palette.lerp(palette.black, palette.white, Mathf.Clamp(projVal + 1500f, 0, 9000) / 9000f);
                                }
                            }

                            if ((i > 0 && mapline[i - 1] != bio) || (mapstep > 0 && mapline[i] != bio))
                            {
                                biome = palette.white;
                            }
                            else if (SCANcontroller.controller.useStockBiomes)
                            {
                                Color c = SCANUtil.getBiome(body, lon, lat).mapColor;
                                biome = palette.lerp(c, elevation, SCANcontroller.controller.biomeTransparency / 100f);
                            }
                            else
                            {
                                biome = palette.lerp(palette.lerp(SCANcontroller.controller.lowBiomeColor, SCANcontroller.controller.highBiomeColor, (float)bio), elevation, SCANcontroller.controller.biomeTransparency / 100f);
                            }
                        }

                        baseColor  = biome;
                        mapline[i] = bio;
                    }
                    if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null)
                    {
                        pix[i] = SCANuiUtil.resourceToColor(lon, lat, data, baseColor, resource);
                    }
                    else
                    {
                        pix[i] = baseColor;
                    }
                }
            }
            map.SetPixels(0, mapstep, map.width, 1, pix);
            mapstep++;
            if (mapstep % 10 == 0 || mapstep >= map.height)
            {
                map.Apply();
            }
            return(map);
        }
        private void topBar(int id)
        {
            growE();
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                GUILayout.Label("", GUILayout.Width(70));
            }
            else
            {
                if (v != null)
                {
                    showOrbit = GUILayout.Toggle(showOrbit, textWithTT("", "Toggle Orbit"));

                    Rect d = GUILayoutUtility.GetLastRect();
                    d.x     += 30;
                    d.y     += 2;
                    d.width  = 40;
                    d.height = 20;

                    if (GUI.Button(d, iconWithTT(SCANskins.SCAN_OrbitIcon, "Toggle Orbit"), SCANskins.SCAN_buttonBorderless))
                    {
                        showOrbit = !showOrbit;
                    }
                }
                else
                {
                    GUILayout.Label("", GUILayout.Width(10));
                }

                if (SCANcontroller.controller.mechJebTargetSelection)
                {
                    if (SCANcontroller.controller.MechJebLoaded && SCANcontroller.controller.LandingTargetBody == b)
                    {
                        fillS(50);
                        if (GUILayout.Button(textWithTT("", "Set MechJeb Target"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(24), GUILayout.Height(24)))
                        {
                            SCANcontroller.controller.TargetSelecting = !SCANcontroller.controller.TargetSelecting;
                        }
                        Rect  r   = GUILayoutUtility.GetLastRect();
                        Color old = GUI.color;
                        GUI.color = palette.red;
                        GUI.DrawTexture(r, SCANskins.SCAN_MechJebIcon);
                        GUI.color = old;
                    }
                    else
                    {
                        GUILayout.Label("", GUILayout.Width(70));
                    }
                }
                else
                {
                    fillS(50);
                    if (GUILayout.Button(textWithTT("", "Set Landing Target"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(24), GUILayout.Height(24)))
                    {
                        SCANcontroller.controller.TargetSelecting = !SCANcontroller.controller.TargetSelecting;
                    }
                    Rect  r   = GUILayoutUtility.GetLastRect();
                    Color old = GUI.color;
                    GUI.color = palette.xkcd_PukeGreen;
                    GUI.DrawTexture(r, SCANskins.SCAN_TargetIcon);
                    GUI.color = old;
                }
            }

            fillS();

            if (GUILayout.Button(iconWithTT(SCANskins.SCAN_ZoomOutIcon, "Zoom Out"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(26), GUILayout.Height(26)))
            {
                spotmap.MapScale = spotmap.MapScale / 1.25f;
                if (spotmap.MapScale < 2)
                {
                    spotmap.MapScale = 2;
                }
                resetMap();
            }

            if (GUILayout.Button(textWithTT(spotmap.MapScale.ToString("N1") + " X", "Sync To Big Map"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(50), GUILayout.Height(24)))
            {
                SCANcontroller.controller.TargetSelecting       = false;
                SCANcontroller.controller.TargetSelectingActive = false;

                if (bigmap.Projection == MapProjection.Polar)
                {
                    spotmap.setProjection(MapProjection.Polar);
                }
                else
                {
                    spotmap.setProjection(MapProjection.Rectangular);
                }

                if (bigmap.Body != b)
                {
                    SCANdata dat = SCANUtil.getData(bigmap.Body);
                    if (dat == null)
                    {
                        dat = new SCANdata(bigmap.Body);
                    }

                    data = dat;
                    b    = data.Body;

                    spotmap.setBody(b);
                }

                if (SCANconfigLoader.GlobalResource && narrowBand)
                {
                    spotmap.Resource = bigmap.Resource;
                    spotmap.Resource.CurrentBodyConfig(b.name);
                }

                spotmap.centerAround(spotmap.CenteredLong, spotmap.CenteredLat);
                if (SCANcontroller.controller.needsNarrowBand && SCANcontroller.controller.map_ResourceOverlay)
                {
                    checkForScanners();
                }
                spotmap.resetMap(bigmap.MType, false, narrowBand);
            }

            if (GUILayout.Button(iconWithTT(SCANskins.SCAN_ZoomInIcon, "Zoom In"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(26), GUILayout.Height(26)))
            {
                spotmap.MapScale = spotmap.MapScale * 1.25f;
                resetMap();
            }

            fillS();

            if (HighLogic.LoadedScene != GameScenes.SPACECENTER)
            {
                showWaypoints = GUILayout.Toggle(showWaypoints, textWithTT("", "Toggle Waypoints"));

                Rect w = GUILayoutUtility.GetLastRect();
                w.x     += 28;
                w.y     += 2;
                w.width  = 20;
                w.height = 20;

                if (GUI.Button(w, iconWithTT(SCANskins.SCAN_WaypointIcon, "Toggle Waypoints"), SCANskins.SCAN_buttonBorderless))
                {
                    showWaypoints = !showWaypoints;
                }

                fillS(16);
            }
            else
            {
                GUILayout.Label("", GUILayout.Width(40));
            }

            showAnomaly = GUILayout.Toggle(showAnomaly, textWithTT("", "Toggle Anomalies"));

            Rect a = GUILayoutUtility.GetLastRect();

            a.x     += 26;
            a.y     += 2;
            a.width  = 20;
            a.height = 20;

            if (GUI.Button(a, textWithTT(SCANcontroller.controller.anomalyMarker, "Toggle Anomalies"), SCANskins.SCAN_buttonBorderless))
            {
                showAnomaly = !showAnomaly;
            }

            fillS(16);

            stopE();
        }
Exemple #17
0
        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);
        }
Exemple #18
0
        protected override void LateUpdate()
        {
            if (shutdown)
            {
                return;
            }

            if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready)
            {
                return;
            }

            if (SCANcontroller.controller == null)
            {
                way = null;
                return;
            }

            if (!SCANcontroller.controller.mechJebTargetSelection)
            {
                way = null;
                return;
            }

            v = FlightGlobals.ActiveVessel;

            if (v == null)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            if (v.mainBody != SCANcontroller.controller.LandingTargetBody)
            {
                SCANcontroller.controller.LandingTargetBody = v.mainBody;
            }

            data = SCANUtil.getData(v.mainBody);

            if (data == null)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            if (v.FindPartModulesImplementing <MechJebCore>().Count <= 0)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            core = v.GetMasterMechJeb();

            if (core == null)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
            {
                if (guidanceModule == null)
                {
                    guidanceModule = (DisplayModule)core.GetComputerModule("MechJebModuleLandingGuidance");
                }

                if (guidanceModule == null)
                {
                    SCANcontroller.controller.MechJebLoaded = false;
                    way = null;
                    return;
                }

                if (!guidanceModule.unlockChecked)
                {
                    return;
                }

                if (guidanceModule.hidden)
                {
                    SCANcontroller.controller.MechJebLoaded = false;
                    shutdown = true;
                    way      = null;
                    return;
                }
            }

            target = core.target;

            if (target == null)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            if (!SCANcontroller.controller.MechJebLoaded)
            {
                SCANcontroller.controller.MechJebLoaded = true;
                RenderingManager.AddToPostDrawQueue(1, drawTarget);
            }

            if (SCANcontroller.controller.LandingTarget != null)
            {
                way = SCANcontroller.controller.LandingTarget;
            }

            if (SCANcontroller.controller.TargetSelecting)
            {
                way             = null;
                selectingTarget = true;
                if (SCANcontroller.controller.TargetSelectingActive)
                {
                    selectingInMap = true;
                }
                else
                {
                    selectingInMap = false;
                }
                coords = SCANcontroller.controller.LandingTargetCoords;
                return;
            }
            else if (selectingTarget)
            {
                selectingTarget = false;
                if (selectingInMap)
                {
                    selectingInMap = false;
                    coords         = SCANcontroller.controller.LandingTargetCoords;
                    way            = new SCANwaypoint(coords.y, coords.x, siteName);
                    target.SetPositionTarget(SCANcontroller.controller.LandingTargetBody, way.Latitude, way.Longitude);
                }
            }

            selectingInMap  = false;
            selectingTarget = false;

            if (target.Target == null)
            {
                way = null;
                return;
            }

            if (target.targetBody != v.mainBody)
            {
                way = null;
                return;
            }

            if (!(target.Target is PositionTarget))
            {
                way = null;
                return;
            }

            coords.x = target.targetLongitude;
            coords.y = target.targetLatitude;

            if (way != null)
            {
                if (!SCANUtil.ApproxEq(coords.x, way.Longitude) || !SCANUtil.ApproxEq(coords.y, way.Latitude))
                {
                    way = new SCANwaypoint(coords.y, coords.x, siteName);
                    SCANcontroller.controller.LandingTarget = way;
                    data.addToWaypoints();
                }
            }
            else
            {
                way = new SCANwaypoint(coords.y, coords.x, siteName);
                SCANcontroller.controller.LandingTarget = way;
                data.addToWaypoints();
            }
        }