Ejemplo n.º 1
0
        public static Bitmap ToDebugBitmap(this ImageData imgData, float scale = 50.0f, List <Unit> units = null, ToDebugBitmapOption options = null)
        {
            if (options == null)
            {
                options = new ToDebugBitmapOption();
            }
            //Font drawFont = new Font("Arial", 10);
            Pen      pen = new Pen(System.Drawing.Color.Yellow, 1);
            Bitmap   bv  = new Bitmap((int)(imgData.Size.X * scale), (int)(imgData.Size.Y * scale), PixelFormat.Format32bppArgb);
            Graphics g   = Graphics.FromImage(bv);

            g.Clear(System.Drawing.Color.Black);
            for (int x = 0; x < imgData.Size.X; x++)
            {
                for (int y = 0; y < imgData.Size.Y; y++)
                {
                    byte value = imgData.GetValue(x, y);
                    if (options.flgColor)
                    {
                        System.Drawing.Color color = System.Drawing.Color.FromArgb(value, value, value);
                        switch (value)
                        {
                        case 127: color = System.Drawing.Color.Black; break;

                        case 134: color = System.Drawing.Color.Orange; break;

                        case 135: color = System.Drawing.Color.Cyan; break;

                        case 143: color = System.Drawing.Color.LightGray; break;

                        case 142: color = System.Drawing.Color.Green; break;

                        case 141: color = System.Drawing.Color.Lime; break;

                        case 140: color = System.Drawing.Color.Gray; break;
                        }
                        g.FillRectangle(new SolidBrush(color), new Rectangle((int)Math.Round(x * scale), (int)Math.Round(y * scale), (int)Math.Round(scale), (int)Math.Round(scale)));
                    }
                    if (options.flgDrawValue)
                    {
                        g.DrawString("" + value, drawFont, drawBrushYellow, new PointF((float)(x) * scale, (float)(y + 0.5) * scale));
                    }
                    if (options.flgDrawGridPos)
                    {
                        g.DrawString(String.Format("{0},{1}", x, imgData.Size.Y - y), drawFont, drawBrushWhite, new PointF((float)(x) * scale, (float)(y) * scale));
                    }
                }
            }
            if (options.flgDrawGrid)
            {
                for (int x = 0; x < imgData.Size.X; x++)
                {
                    int px = (int)(x * scale);
                    g.DrawLine(pen, px, 0, px, bv.Height);
                }
                for (int y = 0; y < imgData.Size.Y; y++)
                {
                    int py = (int)(y * scale);
                    g.DrawLine(pen, 0, py, bv.Width, py);
                }
            }
            if (units != null)
            {
                DrawUnits(g, imgData.Size.Y, scale, units, options);
            }
            g.Save();
            g.Dispose();
            return(bv);
        }
Ejemplo n.º 2
0
        public static void DrawUnits(Graphics g, int gameY, float scale, List <Unit> units, ToDebugBitmapOption option = null)
        {
            foreach (Unit u in units)
            {
                Pen pen = penWhite;
                switch (u.Alliance)
                {
                case Alliance.Enemy: pen = penRed; break;

                case Alliance.Neutral: pen = penGreen; break;

                case Alliance.Self: pen = penBlue; break;
                }
                System.Drawing.Point myPoint = u.Pos.ToTopLeftPoint(gameY, scale);
                if (u.DisplayType == DisplayType.Snapshot)
                {
                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                    g.DrawCircle(pen, myPoint.X, myPoint.Y, u.Radius * scale);
                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                }
                else
                {
                    g.DrawCircle(pen, myPoint.X, myPoint.Y, u.Radius * scale);
                }
                if (option != null)
                {
                    if (option.flgDrawTarget)
                    {
                        foreach (var o in u.Orders)
                        {
                            Pen targetPen = pen;
                            SC2APIProtocol.Point targetPoint = o.TargetWorldSpacePos;
                            if (o.TargetUnitTag != 0)
                            {
                                Unit targtUint = units.GetUnit(o.TargetUnitTag);
                                if (targtUint != null)
                                {
                                    targetPen   = penWhite;
                                    targetPoint = targtUint.Pos;
                                }
                            }
                            if (targetPoint != null)
                            {
                                System.Drawing.Point drawTargetPoint = targetPoint.ToTopLeftPoint(gameY, scale);
                                if (targetPen == penWhite)
                                {
                                    g.DrawCircle(targetPen, myPoint.X, myPoint.Y, 2);
                                }
                                targetPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                                g.DrawLine(targetPen, myPoint, drawTargetPoint);
                                targetPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                            }
                        }
                    }
                }
            }
        }