示例#1
0
        public float drawSlider(bool under, ref float value)
        {
            GUILayout.Label(title + value + units, SCANskins.SCAN_whiteReadoutLabel);

            Rect r = GUILayoutUtility.GetLastRect();

            r.x    += 110;
            r.width = 260;

            if (under)
            {
                GUI.HorizontalSlider(r, value, minValue, maxValue).Mathf_Round(precision);
            }
            else
            {
                value = GUI.HorizontalSlider(r, value, minValue, maxValue).Mathf_Round(precision);
            }

            int    i = precision <= 0 ? 0 : precision;
            string labelPrecision = "F" + i.ToString();

            SCANuiUtil.drawSliderLabel(r, minValue.ToString(labelPrecision) + units, maxValue.ToString(labelPrecision) + units);

            currentValue = value;

            return(value);
        }
示例#2
0
        //Display info for mouse over in the map and handle the zoom map
        private void mouseOver(int id)
        {
            float  mx = Event.current.mousePosition.x - TextureRect.x;
            float  my = Event.current.mousePosition.y - TextureRect.y;
            bool   in_map = false;
            double mlon = 0, mlat = 0;

            //Draw the re-size label in the corner
            Rect resizer = new Rect(WindowRect.width - 24, WindowRect.height - 26, 24, 24);

            GUI.Label(resizer, SCANskins.SCAN_ResizeIcon);

            //Handles mouse positioning and converting to lat/long coordinates
            if (mx >= 0 && my >= 0 && mx < MapTexture.width && my < MapTexture.height)
            {
                double mlo = (mx * 360f / MapTexture.width) - 180;
                double mla = 90 - (my * 180f / MapTexture.height);
                mlon = bigmap.unprojectLongitude(mlo, mla);
                mlat = bigmap.unprojectLatitude(mlo, mla);

                if (mlon >= -180 && mlon <= 180 && mlat >= -90 && mlat <= 90)
                {
                    in_map = true;
                }
            }

            //Handles mouse click while inside map; opens zoom map
            if (Event.current.isMouse && !ddRect.Contains(Event.current.mousePosition) && !zoomCloseRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseUp)
                {
                    if (Event.current.button == 1)
                    {
                        if (in_map)
                        {
                            if (spotMap == null)
                            {
                                spotMap = gameObject.AddComponent <SCANzoomWindow>();
                            }
                            spotMap.setMapCenter(mlat, mlon, bigmap);
                        }
                        Event.current.Use();
                    }
                }
                //Handle clicking inside the re-size button
                else if (Event.current.isMouse &&
                         Event.current.type == EventType.MouseDown &&
                         Event.current.button == 0 &&
                         resizer.Contains(Event.current.mousePosition))
                {
                    IsResizing = true;
                    dragX      = Input.mousePosition.x;
                    resizeW    = TextureRect.width;
                    Event.current.Use();
                }
            }

            //Draw the actual mouse over info label below the map
            SCANuiUtil.mouseOverInfo(mlon, mlat, bigmap, data, bigmap.Body, in_map);
        }
        internal void drawColorSelector(Rect R)
        {
            GUILayout.Space(20);
            GUILayout.BeginVertical();
            GUILayout.Label("Color Selection", SCANskins.SCAN_headline);
            GUILayout.BeginHorizontal();
            GUILayout.Space(30);
            GUILayout.Label(SCANskins.SCAN_BigColorWheel);
            Rect r = GUILayoutUtility.GetLastRect();

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            Rect s = new Rect(r.x + 170, r.y + 100, 80, 30);

            GUI.Label(s, "Value: " + valSlider.ToString("N0") + "%", SCANskins.SCAN_whiteReadoutLabel);

            s.x      += 80;
            s.y      -= 90;
            s.width   = 30;
            s.height  = 200;
            valSlider = GUI.VerticalSlider(s, valSlider, 100, 0, SCANskins.SCAN_vertSlider, SCANskins.SCAN_sliderThumb).Mathf_Round(0);

            SCANuiUtil.drawVerticalSliderLabel(s, "0%", "100%");

            if (GUI.RepeatButton(r, "", SCANskins.SCAN_colorWheelButton))
            {
                int a = (int)Input.mousePosition.x;
                int b = Screen.height - (int)Input.mousePosition.y;

                c = SCANskins.SCAN_BigColorWheel.GetPixel(a - (int)R.x - (int)r.x, -(b - (int)R.y - (int)r.y));

                if (lowColorChange)
                {
                    colorLow = c * new Color(valSlider / 100f, valSlider / 100f, valSlider / 100f);
                }
                else
                {
                    colorHigh = c * new Color(valSlider / 100f, valSlider / 100f, valSlider / 100f);
                }
            }

            r.x     -= 55;
            r.y     += 145;
            r.width  = 60;
            r.height = 30;

            colorSwatches(r, "Low", ref lowColorChange, true, minColorPreview, minColorOld, colorLow);

            r.x += 150;
            colorSwatches(r, "High", ref lowColorChange, false, maxColorPreview, maxColorOld, colorHigh);

            r.x -= 60;
            r.y += 30;
            GUI.Label(r, "New", SCANskins.SCAN_headlineSmall);

            r.y += 32;
            GUI.Label(r, "Old", SCANskins.SCAN_headlineSmall);
        }
示例#4
0
 //Draw the orbit overlays
 private void drawOrbit(int id)
 {
     if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
     {
         if (SCANcontroller.controller.map_orbit && v != null)
         {
             SCANuiUtil.drawOrbit(TextureRect, bigmap, v, bigmap.Body);
         }
     }
 }
        private void mapLabels(int id)
        {
            //Draw the orbit overlays
            if (showOrbit && v != null)
            {
                SCANuiUtil.drawOrbit(TextureRect, spotmap, v, spotmap.Body);
            }

            SCANuiUtil.drawMapLabels(TextureRect, v, spotmap, data, spotmap.Body, showAnomaly, showWaypoints);
        }
        //Display info on the nearest anomaly *Need to separate the BTDT display*
        private void anomalyInfo(int id)
        {
            if ((sensors & SCANtype.AnomalyDetail) != SCANtype.Nothing)
            {
                SCANanomaly nearest      = null;
                double      nearest_dist = -1;
                foreach (SCANanomaly a in data.Anomalies)
                {
                    if (!a.Known)
                    {
                        continue;
                    }
                    double d = (a.Mod.transform.position - v.transform.position).magnitude;
                    if (d < nearest_dist || nearest_dist < 0)
                    {
                        if (d < 50000)
                        {
                            nearest      = a;
                            nearest_dist = d;
                        }
                    }
                }
                if (nearest != null)
                {
                    string txt = "Anomaly";
                    if (nearest.Detail)
                    {
                        txt = nearest.Name;
                    }
                    txt += ":  " + SCANuiUtil.distanceString(nearest_dist, 5000);
                    GUILayout.Label(txt, SCANskins.SCAN_insColorLabel);

                    if (anomalyView == null)
                    {
                        anomalyView = new SCANremoteView();
                    }
                    if (anomalyView != null)
                    {
                        if (nearest.Mod != null)
                        {
                            if (anomalyView.lookat != nearest.Mod.gameObject)
                            {
                                anomalyView.setup(320, 240, nearest.Mod.gameObject);
                            }
                            Texture t = anomalyView.getTexture();
                            if (t != null)
                            {
                                GUILayout.Label(anomalyView.getTexture());
                                anomalyView.drawOverlay(GUILayoutUtility.GetLastRect(), SCANskins.SCAN_anomalyOverlay, nearest.Detail);
                            }
                        }
                    }
                }
            }
        }
示例#7
0
        //Draw the map overlay labels
        private void mapLabels(int id)
        {
            bool showWaypoints = false;

            if (waypoints)
            {
                showWaypoints = SCANcontroller.controller.map_waypoints;
            }

            SCANuiUtil.drawMapLabels(TextureRect, v, bigmap, data, bigmap.Body, SCANcontroller.controller.map_markers, showWaypoints);
        }
示例#8
0
 //Draw the altitude legend bar along the bottom
 private void legendBar(int id)
 {
     if (bigmap.MType == mapType.Altimetry && SCANcontroller.controller.legend)
     {
         if (bigmap.MapLegend == null)
         {
             bigmap.MapLegend = new SCANmapLegend();
         }
         bigmap.MapLegend.Legend = bigmap.MapLegend.getLegend(data.TerrainConfig.MinTerrain, data.TerrainConfig.MaxTerrain, SCANcontroller.controller.colours, data);
         SCANuiUtil.drawLegend(data, bigmap.MapLegend);
     }
 }
示例#9
0
        //Draw the active scanner display
        private void scannerInfo(int id)
        {
            bool repainting = Event.current.type == EventType.Repaint;

            if (!repainting)
            {
                infoText = SCANuiUtil.InfoText(v, data, notMappingToday);
            }

            if (infoText != null)
            {
                SCANuiUtil.readableLabel(infoText, false);
            }
        }
示例#10
0
        private void DrawIcon(SCANwaypoint p, Color iconColor)
        {
            Rect pos = new Rect((float)(longitudeToPixels(p.Longitude, p.Latitude)), (float)(latitudeToPixels(p.Longitude, p.Latitude)), 16, 16);

            if (!p.LandingTarget)
            {
                pos.x -= 8;
                pos.y -= 16;
                SCANuiUtil.drawMapIconGL(pos, SCANskins.SCAN_WaypointIcon, iconColor, iconMaterial, iconColorShadowValue, true);
            }
            else
            {
                pos.x -= 8;
                pos.y -= 8;
                SCANuiUtil.drawMapIconGL(pos, SCANcontroller.controller.mechJebTargetSelection ? SCANskins.SCAN_MechJebIcon : SCANskins.SCAN_TargetIcon, iconColor, iconMaterial, iconColorShadowValue, true);
            }
        }
示例#11
0
        //Draw the actual map texture
        private void mapDraw(int id)
        {
            MapTexture = bigmap.getPartialMap();

            GUILayout.Label("", GUILayout.Width(MapTexture.width), GUILayout.Height(MapTexture.height));

            TextureRect        = GUILayoutUtility.GetLastRect();
            TextureRect.width  = bigmap.MapWidth;
            TextureRect.height = bigmap.MapHeight;

            if (drawGrid)
            {
                gridLines = new Dictionary <int, List <List <Vector2d> > >();
                gridLines = SCANuiUtil.drawGridLine(TextureRect, bigmap);
                drawGrid  = false;
            }

            GUI.DrawTexture(TextureRect, MapTexture);

            if (bigmap.Projection == MapProjection.Polar)
            {
                rc.x = TextureRect.x + TextureRect.width / 2 - TextureRect.width / 8;
                rc.y = TextureRect.y + TextureRect.height / 8;
                SCANuiUtil.drawLabel(rc, "S", false, true, true);
                rc.x = TextureRect.x + TextureRect.width / 2 + TextureRect.width / 8;
                SCANuiUtil.drawLabel(rc, "N", false, true, true);
            }

            if (SCANcontroller.controller.map_grid)
            {
                if (gridLines.Count > 0)
                {
                    GL.PushMatrix();
                    foreach (List <Vector2d> points in gridLines[0])
                    {
                        SCANuiUtil.drawGridLines(points, bigmap.MapWidth, TextureRect.x, TextureRect.y, SCANuiUtil.blackLineColor);
                    }
                    foreach (List <Vector2d> points in gridLines[1])
                    {
                        SCANuiUtil.drawGridLines(points, bigmap.MapWidth, TextureRect.x, TextureRect.y, SCANuiUtil.lineColor);
                    }
                    GL.PopMatrix();
                }
            }
        }
示例#12
0
        internal static void drawOrbitIconGL(int x, int y, OrbitIcon icon, Color c, Color shadow, Material iconMat, int size = 32 /*px*/, bool outline = false)
        {
            // PX [0..n]
            // ORIGIN: NorthWest
            pos_icon.x      = x - (size / 2);
            pos_icon.y      = y - (size / 2);
            pos_icon.width  = size;
            pos_icon.height = size;

            // UV [0..1]
            // Origin: SouthWest
            grid_pos.width  = 0.2f;
            grid_pos.height = 0.2f;
            grid_pos.x      = 0.2f * ((int)icon % 5);
            grid_pos.y      = 0.2f * (4 - (int)icon / 5);

            SCANuiUtil.drawMapIconGL(pos_icon, MapView.OrbitIconsMap, c, iconMat, shadow, outline, grid_pos, true);
        }
示例#13
0
        //Display info for mouse over in the map and handle the zoom map
        private void mouseOver(int id)
        {
            float  mx = Event.current.mousePosition.x - TextureRect.x;
            float  my = Event.current.mousePosition.y - TextureRect.y;
            bool   in_map = false;
            double mlon = 0, mlat = 0;

            //Handles mouse positioning and converting to lat/long coordinates
            if (mx >= 0 && my >= 0 && mx < MapTexture.width && my < MapTexture.height)
            {
                double mlo = (mx * 360f / MapTexture.width) - 180;
                double mla = 90 - (my * 180f / MapTexture.height);
                mlon = bigmap.unprojectLongitude(mlo, mla);
                mlat = bigmap.unprojectLatitude(mlo, mla);

                if (mlon >= -180 && mlon <= 180 && mlat >= -90 && mlat <= 90)
                {
                    in_map = true;
                }
            }

            //Handles mouse click while inside map; opens zoom map or zooms in further
            if (Event.current.isMouse && !ddRect.Contains(Event.current.mousePosition) && !zoomCloseRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseUp)
                {
                    if (Event.current.button == 1)
                    {
                        if (in_map)
                        {
                            if (spotMap == null)
                            {
                                spotMap = gameObject.AddComponent <SCANzoomWindow>();
                            }
                            spotMap.setMapCenter(mlat, mlon, bigmap);
                        }
                    }
                    Event.current.Use();
                }
            }

            //Draw the actual mouse over info label below the map
            SCANuiUtil.mouseOverInfo(mlon, mlat, bigmap, data, bigmap.Body, in_map);
        }
示例#14
0
 //Method to handle vessel info
 private bool vesselInfo(Vessel scanV, Rect r, int i, bool b)
 {
     if (scanV == null)
     {
         return(false);
     }
     if (scanV.mainBody == v.mainBody)
     {
         if (!showVesselInfo)
         {
             SCANuiUtil.drawVesselLabel(r, null, -1, scanV);
             return(true);
         }
         float lon = (float)SCANUtil.fixLonShift(scanV.longitude);
         float lat = (float)SCANUtil.fixLatShift(scanV.latitude);
         float alt = scanV.heightFromTerrain;
         if (alt < 0)
         {
             alt = (float)scanV.altitude;
         }
         string text = string.Format("[{0}] {1} ({2:F1}°,{3:F1}°; {4:N1}m)", i, scanV.vesselName, lat, lon, alt);
         if (SCANuiUtil.readableLabel(text, b))
         {
             if (Event.current.clickCount > 1)
             {
                 Event.current.Use();
                 FlightGlobals.SetActiveVessel(scanV);
                 ScreenMessages.PostScreenMessage(scanV.vesselName, 5, ScreenMessageStyle.UPPER_CENTER);
             }
         }
         SCANuiUtil.drawVesselLabel(r, null, i, scanV);
         fillS(-10);
         return(true);
     }
     return(false);
 }
示例#15
0
        private void mapDraw(int id)
        {
            MapTexture = bigmap.getPartialMap();

            //A blank label used as a template for the actual map texture
            if (IsResizing)
            {
                //Set minimum map size during re-sizing
                dW = resizeW;
                if (dW < WindowSize_Min.x)
                {
                    dW = WindowSize_Min.x;
                }
                dH = dW / 2f;
                GUILayout.Label("", GUILayout.Width(dW), GUILayout.Height(dH));
            }
            else
            {
                GUILayout.Label("", GUILayout.Width(MapTexture.width), GUILayout.Height(MapTexture.height));
            }

            TextureRect        = GUILayoutUtility.GetLastRect();
            TextureRect.width  = bigmap.MapWidth;
            TextureRect.height = bigmap.MapHeight;

            //Generate the grid lines
            if (drawGrid)
            {
                gridLines = new Dictionary <int, List <List <Vector2d> > >();
                gridLines = SCANuiUtil.drawGridLine(TextureRect, bigmap);
                drawGrid  = false;
            }

            //Stretches the existing map while re-sizing
            if (IsResizing)
            {
                TextureRect.width  = dW;
                TextureRect.height = dH;
                GUI.DrawTexture(TextureRect, MapTexture, ScaleMode.StretchToFill);
            }
            else
            {
                GUI.DrawTexture(TextureRect, MapTexture);
            }

            //Add the North/South labels to the polar projection
            if (bigmap.Projection == MapProjection.Polar)
            {
                rc.x = TextureRect.x + TextureRect.width / 2 - TextureRect.width / 8;
                rc.y = TextureRect.y + TextureRect.height / 8;
                SCANuiUtil.drawLabel(rc, "S", false, true, true);
                rc.x = TextureRect.x + TextureRect.width / 2 + TextureRect.width / 8;
                SCANuiUtil.drawLabel(rc, "N", false, true, true);
            }

            if (SCANcontroller.controller.map_grid && !IsResizing)
            {
                if (gridLines.Count > 0)
                {
                    GL.PushMatrix();
                    foreach (List <Vector2d> points in gridLines[0])
                    {
                        SCANuiUtil.drawGridLines(points, bigmap.MapWidth, TextureRect.x, TextureRect.y, SCANuiUtil.blackLineColor);
                    }
                    foreach (List <Vector2d> points in gridLines[1])
                    {
                        SCANuiUtil.drawGridLines(points, bigmap.MapWidth, TextureRect.x, TextureRect.y, SCANuiUtil.lineColor);
                    }
                    GL.PopMatrix();
                }
            }

            //Draw the orbit overlays
            if (SCANcontroller.controller.map_orbit)
            {
                SCANuiUtil.drawOrbit(TextureRect, bigmap, v, bigmap.Body);
            }
        }
示例#16
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);
        }
示例#17
0
 //Draw the map overlay labels
 private void mapLabels(int id)
 {
     SCANuiUtil.drawMapLabels(TextureRect, v, bigmap, data, bigmap.Body, SCANcontroller.controller.map_markers, SCANcontroller.controller.map_waypoints);
 }
示例#18
0
        private void mouseOver(int id)
        {
            float  mx = Event.current.mousePosition.x - TextureRect.x;
            float  my = Event.current.mousePosition.y - TextureRect.y;
            bool   in_map = false;
            double mlon = 0, mlat = 0;

            //Draw the re-size label in the corner
            Rect resizer = new Rect(WindowRect.width - 24, WindowRect.height - 26, 24, 24);

            GUI.Label(resizer, SCANskins.SCAN_ResizeIcon);

            //Handles mouse positioning and converting to lat/long coordinates
            if (mx >= 0 && my >= 0 && mx <= TextureRect.width && my <= TextureRect.height /*mx >= 0 && my >= 0 && mx < MapTexture.width && my < MapTexture.height*/)
            {
                double mlo = spotmap.Lon_Offset + (mx / spotmap.MapScale) - 180;
                double mla = spotmap.Lat_Offset + ((TextureRect.height - my) / spotmap.MapScale) - 90;
                mlon = spotmap.unprojectLongitude(mlo, mla);
                mlat = spotmap.unprojectLatitude(mlo, mla);

                if (mlon >= -180 && mlon <= 180 && mlat >= -90 && mlat <= 90)
                {
                    in_map = true;
                    if (SCANcontroller.controller.TargetSelecting)
                    {
                        SCANcontroller.controller.TargetSelectingActive = true;
                        mjTarget.x = mlon;
                        mjTarget.y = mlat;
                        SCANcontroller.controller.LandingTargetCoords = mjTarget;
                        Rect r = new Rect(mx + TextureRect.x - 11, my + TextureRect.y - 13, 24, 24);
                        SCANuiUtil.drawMapIcon(r, SCANcontroller.controller.mechJebTargetSelection ? SCANskins.SCAN_MechJebIcon : SCANskins.SCAN_TargetIcon, true, palette.yellow, true);
                    }
                }
                else if (SCANcontroller.controller.TargetSelecting)
                {
                    SCANcontroller.controller.TargetSelectingActive = false;
                }

                if (mlat > 90)
                {
                    mlon = (mlon + 360) % 360 - 180;
                    mlat = 180 - mlat;
                }
                else if (mlat < -90)
                {
                    mlon = (mlon + 360) % 360 - 180;
                    mlat = -180 - mlat;
                }
            }
            else if (SCANcontroller.controller.TargetSelecting)
            {
                SCANcontroller.controller.TargetSelectingActive = false;
            }

            //Handles mouse click while inside map
            if (Event.current.isMouse)
            {
                if (Event.current.type == EventType.MouseUp)
                {
                    //Generate waypoint for MechJeb target
                    if (SCANcontroller.controller.TargetSelecting && SCANcontroller.controller.TargetSelectingActive && Event.current.button == 0 && in_map)
                    {
                        string       s = SCANcontroller.controller.mechJebTargetSelection ? "MechJeb Landing Target" : "Landing Target Site";
                        SCANwaypoint w = new SCANwaypoint(mlat, mlon, s);
                        SCANcontroller.controller.LandingTarget = w;
                        data.addToWaypoints();
                        SCANcontroller.controller.TargetSelecting       = false;
                        SCANcontroller.controller.TargetSelectingActive = false;
                    }
                    //Middle click re-center
                    else if (Event.current.button == 2 || (Event.current.button == 1 && GameSettings.MODIFIER_KEY.GetKey()))
                    {
                        if (in_map)
                        {
                            spotmap.centerAround(mlon, mlat);
                            resetMap();
                        }
                    }
                    //Right click zoom in
                    else if (Event.current.button == 1)
                    {
                        if (in_map)
                        {
                            spotmap.MapScale = spotmap.MapScale * 1.25f;
                            spotmap.centerAround(mlon, mlat);
                            resetMap();
                        }
                    }
                    //Left click zoom out
                    else if (Event.current.button == 0)
                    {
                        if (in_map)
                        {
                            spotmap.MapScale = spotmap.MapScale / 1.25f;
                            if (spotmap.MapScale < 2)
                            {
                                spotmap.MapScale = 2;
                            }
                            spotmap.centerAround(mlon, mlat);
                            resetMap();
                        }
                    }
                    Event.current.Use();
                }

                //Handle clicking inside the re-size button
                else if (Event.current.isMouse &&
                         Event.current.type == EventType.MouseDown &&
                         Event.current.button == 0 &&
                         resizer.Contains(Event.current.mousePosition))
                {
                    IsResizing  = true;
                    dragStart.x = Input.mousePosition.x;
                    dragStart.y = Input.mousePosition.y;
                    resizeW     = TextureRect.width;
                    resizeH     = TextureRect.height;
                    Event.current.Use();
                }
            }

            //Draw the actual mouse over info label below the map
            if (SCANcontroller.controller.TargetSelecting)
            {
                SCANuiUtil.readableLabel(SCANcontroller.controller.mechJebTargetSelection ? "MechJeb Landing Guidance Targeting..." : "Landing Site Targeting...", false);
                fillS(-10);
                SCANuiUtil.mouseOverInfoSimple(mlon, mlat, spotmap, data, spotmap.Body, in_map);
            }
            else if (showInfo)
            {
                SCANuiUtil.mouseOverInfoSimple(mlon, mlat, spotmap, data, spotmap.Body, in_map);
            }
            else
            {
                fillS(10);
            }
        }
示例#19
0
        protected override void DrawWindowPre(int id)
        {
            WindowCaption = SCANuiUtil.toDMS(spotmap.CenteredLat, spotmap.CenteredLong);

            if (IsResizing && !inRepaint())
            {
                if (Input.GetMouseButtonUp(0))
                {
                    double scale = spotmap.MapScale;
                    IsResizing = false;
                    if (resizeW < WindowSize_Min.x)
                    {
                        resizeW = WindowSize_Min.x;
                    }
                    else if (resizeW > WindowSize_Max.x)
                    {
                        resizeW = WindowSize_Max.x;
                    }
                    if (resizeH < WindowSize_Min.y)
                    {
                        resizeH = WindowSize_Min.y;
                    }
                    else if (resizeH > WindowSize_Max.y)
                    {
                        resizeH = WindowSize_Max.y;
                    }

                    spotmap.setSize((int)resizeW, (int)resizeH);
                    spotmap.MapScale = scale;
                    spotmap.centerAround(spotmap.CenteredLong, spotmap.CenteredLat);
                    spotmap.resetMap(spotmap.MType, false);
                }
                else
                {
                    float yy = Input.mousePosition.y;
                    float xx = Input.mousePosition.x;
                    if (Input.mousePosition.y < 0)
                    {
                        yy = 0;
                    }
                    if (Input.mousePosition.x < 0)
                    {
                        xx = 0;
                    }

                    resizeH    += dragStart.y - yy;
                    dragStart.y = yy;
                    resizeW    += xx - dragStart.x;
                    dragStart.x = xx;
                }
                if (Event.current.isMouse)
                {
                    Event.current.Use();
                }
            }

            //Lock space center click through
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                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)
                {
                    InputLockManager.RemoveControlLock(lockID);
                    controlLock = false;
                }
            }

            //Lock tracking scene click through
            if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                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)
                {
                    InputLockManager.RemoveControlLock(lockID);
                    controlLock = false;
                }
            }
        }
        //Display the current vessel altitude
        private void altInfo(int id)
        {
            if ((sensors & SCANtype.Altimetry) != SCANtype.Nothing)
            {
                double h   = v.altitude;
                double pqs = 0;
                if (v.mainBody.pqsController != null)
                {
                    pqs = v.PQSAltitude();
                    if (pqs > 0 || !v.mainBody.ocean)
                    {
                        h -= pqs;
                    }
                }
                if (h < 0)
                {
                    h = v.altitude;
                }

                if (v.situation == Vessel.Situations.LANDED || v.situation == Vessel.Situations.SPLASHED || v.situation == Vessel.Situations.PRELAUNCH)
                {
                    GUILayout.Label(string.Format("Terrain: {0:N1}m", pqs), SCANskins.SCAN_insColorLabel);
                }
                else
                {
                    GUILayout.Label(string.Format("Altitude: {0}", SCANuiUtil.distanceString(h, 100000)), SCANskins.SCAN_insColorLabel);
                }
                fillS(-10);

                //Calculate slope less frequently; the rapidly changing value makes it difficult to read otherwise
                if (v.mainBody.pqsController != null)
                {
                    float deltaTime = 1f;
                    if (Time.deltaTime != 0)
                    {
                        deltaTime = TimeWarp.deltaTime / Time.deltaTime;
                    }
                    if (deltaTime > 5)
                    {
                        deltaTime = 5;
                    }
                    if (((Time.time * deltaTime) - lastUpdate) > updateInterval)
                    {
                        lastUpdate = Time.time;

                        /* Slope is calculated using a nine point grid centered 5m around the vessel location
                         * The rise between the vessel location's elevation and each point on the grid is calculated, converted to slope in degrees, and averaged;
                         * Note: Averageing is not the most accurate method
                         */

                        double   latOffset = degreeOffset * Math.Cos(Mathf.Deg2Rad * vlat);
                        double[] e         = new double[9];
                        double[] s         = new double[8];
                        e[0] = pqs;
                        e[1] = SCANUtil.getElevation(v.mainBody, vlon + latOffset, vlat);
                        e[2] = SCANUtil.getElevation(v.mainBody, vlon - latOffset, vlat);
                        e[3] = SCANUtil.getElevation(v.mainBody, vlon, vlat + degreeOffset);
                        e[4] = SCANUtil.getElevation(v.mainBody, vlon, vlat - degreeOffset);
                        e[5] = SCANUtil.getElevation(v.mainBody, vlon + latOffset, vlat + degreeOffset);
                        e[6] = SCANUtil.getElevation(v.mainBody, vlon + latOffset, vlat - degreeOffset);
                        e[7] = SCANUtil.getElevation(v.mainBody, vlon - latOffset, vlat + degreeOffset);
                        e[8] = SCANUtil.getElevation(v.mainBody, vlon - latOffset, vlat - degreeOffset);

                        /* Calculate rise for each point on the grid
                         * The distance is 5m for adjacent points and 7.071m for the points on the corners
                         * Rise is converted to slope; i.e. a 5m elevation change over a 5m distance is a rise of 1
                         * Converted to slope using the inverse tangent this gives a slope of 45°
                         * */
                        for (int i = 1; i <= 4; i++)
                        {
                            s[i - 1] = Math.Atan((Math.Abs(e[i] - e[0])) / 5) * Mathf.Rad2Deg;
                        }
                        for (int i = 5; i <= 8; i++)
                        {
                            s[i - 1] = Math.Atan((Math.Abs(e[i] - e[0])) / 7.071) * Mathf.Rad2Deg;
                        }

                        slopeAVG = s.Sum() / 8;
                    }

                    GUILayout.Label(string.Format("Slope: {0:F2}°", slopeAVG), SCANskins.SCAN_insColorLabel);
                    fillS(-10);
                }
            }
        }