Exemplo n.º 1
0
 public void DrawUnit(Graphics g, MapCell cell, SRCCore.Units.Unit u, Rectangle destRect)
 {
     using var image = DrawUnit(cell, u);
     if (image != null)
     {
         g.DrawImage(image, destRect);
     }
 }
Exemplo n.º 2
0
        private Image DrawUnit(MapCell cell, SRCCore.Units.Unit u, bool use_orig_color = false)
        {
            var image      = new Bitmap(MapCellPx, MapCellPx);
            var destRect   = new Rectangle(0, 0, MapCellPx, MapCellPx);
            var emit_light = false;

            // ユニットが自分で発光しているかをあらかじめチェック
            if (Map.MapDrawMode == "夜" && !Map.MapDrawIsMapOnly && !use_orig_color && u.IsFeatureAvailable("発光"))
            {
                emit_light = true;
            }

            using var g = Graphics.FromImage(image);
            // タイル
            switch (u.Party0 ?? "")
            {
            case "味方":
            case "NPC":
                g.DrawImage(picUnit.Image, destRect);
                break;

            case "敵":
                g.DrawImage(picEnemy.Image, destRect);
                break;

            case "中立":
                g.DrawImage(picNeautral.Image, destRect);
                break;
            }

            var unitImage = ImageBuffer.GetTransparent(u.CurrentForm().CurrentBitmap());

            // (発光している場合は2度塗りを防ぐため描画しない)
            if (unitImage != null && !emit_light)
            {
                g.DrawImage(unitImage, destRect);
            }

            // TODO Impl フィルタ
            // フィルタ
            //            if (u.IsFeatureAvailable(ref "地形ユニット"))
            //            {
            //                // 地形ユニットの場合は画像をそのまま使う
            //                ret = BitBlt(withBlock.picTmp32(1).hDC, 0, 0, 32, 32, withBlock.picTmp32(0).hDC, 0, 0, SRCCOPY);
            //            }
            //            else
            //            {
            //                // BitBltを使ってユニット画像とタイルを重ね合わせる

            //                // マスクを作成
            //                Graphics.MakeMask(ref withBlock.picTmp32(0).hDC, ref withBlock.picTmp32(2).hDC, ref 32, ref 32, ref ColorTranslator.ToOle(Color.White));


            //                // 画像の重ね合わせ
            //                // (発光している場合は2度塗りを防ぐため描画しない)
            //                if (!emit_light)
            //                {
            //                    ret = BitBlt(withBlock.picTmp32(1).hDC, 0, 0, 32, 32, withBlock.picTmp32(2).hDC, 0, 0, SRCERASE);
            //                    ret = BitBlt(withBlock.picTmp32(1).hDC, 0, 0, 32, 32, withBlock.picTmp32(0).hDC, 0, 0, SRCINVERT);
            //                }
            //            }
            // 色をステージの状況に合わせて変更
            if (!use_orig_color && !Map.MapDrawIsMapOnly)
            {
                switch (Map.MapDrawMode ?? "")
                {
                case "夜":
                    image.Dark();
                    // ユニットが"発光"の特殊能力を持つ場合、
                    // ユニット画像を、暗くしたタイル画像の上に描画する。
                    if (emit_light)
                    {
                        if (unitImage != null)
                        {
                            g.DrawImage(unitImage, destRect);
                        }
                    }
                    break;

                case "セピア":
                    image.Sepia();
                    break;

                case "白黒":
                    image.Monotone();
                    break;

                case "夕焼け":
                    image.Sunset();
                    break;

                case "水中":
                    image.Water();
                    break;

                case "フィルタ":
                    image.ColorFilter(Map.MapDrawFilterColor, (float)Map.MapDrawFilterTransPercent);
                    break;
                }
            }

            // 行動済のフィルタ
            if (u.Action <= 0 && !u.IsFeatureAvailable("地形ユニット"))
            {
                // 行動済のユニット
                g.FillRectangle(UnitMaskBrush, destRect);
            }

            // ユニットのいる場所に合わせて表示を変更
            var unitAreaPen = Pens.Black;

            switch (u.Area ?? "")
            {
            case "空中":
                // XXX Cellサイズに対応する
                g.DrawLine(unitAreaPen,
                           destRect.Left, destRect.Top + 28,
                           destRect.Left + 31, destRect.Top + 28);
                break;

            case "水中":
                g.DrawLine(unitAreaPen,
                           destRect.Left, destRect.Top + 3,
                           destRect.Left + 31, destRect.Top + 3);
                break;

            case "地中":
                g.DrawLine(unitAreaPen,
                           destRect.Left, destRect.Top + 28,
                           destRect.Left + 31, destRect.Top + 28);
                g.DrawLine(unitAreaPen,
                           destRect.Left, destRect.Top + 3,
                           destRect.Left + 31, destRect.Top + 3);
                break;

            case "宇宙":
                if (cell.Terrain.Class == "月面")
                {
                    g.DrawLine(unitAreaPen,
                               destRect.Left, destRect.Top + 28,
                               destRect.Left + 31, destRect.Top + 28);
                }
                break;
            }

            return(image);
        }