示例#1
0
        internal static void drawOrbitIcon(int x, int y, OrbitIcon icon, Color c, int size = 32 /*px*/, bool outline = false)
        {
            var old = GUI.color;

            // 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.drawMapIcon(pos_icon, MapView.OrbitIconsMap, outline, c, true, grid_pos, true);
        }
        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);
            }
        }