public static void Initialize(GraphicsDeviceManager graphiceDeviceManager,
                               ContentManager content, SpriteBatch spriteBatch)
 {
     ContentExt.Initailize(content);
     GraphicsExt.Initailize(graphiceDeviceManager, spriteBatch);
 }
Exemple #2
0
        private static async Task <Datum> DrawCardAsync(Datum cardBase, InnoTypes tp)
        {
            try
            {
                return(cardBase);

                var cardResponce = await GetObjDataAsync(cardBase.Id);

                var cardData = cardResponce?.Data;

                if (cardData == null)
                {
                    return(null);
                }
                if (tp == InnoTypes.Technopark && cardResponce.Data.TechnoparkStatusID != 4702)
                {
                    return(null);
                }

                var tpName = Enum.GetName(typeof(InnoTypes), tp).ToLower();
                var bgPath = string.Join(Path.DirectorySeparatorChar.ToString(),
                                         new[] { "Resource", "Img", "card_back", $"imo_{tpName}.png" });

                if (!File.Exists(bgPath))
                {
                    Console.WriteLine($"Нет ресурсов - бекграунд {tpName}");
                }

                using (var bg = Image.FromFile(bgPath))
                //  using (var bmp = new Bitmap(bg.Width, bg.Height, PixelFormat.Format32bppPArgb))
                {
                    using (Graphics graphics = Graphics.FromImage(bg))
                    {
                        graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                        //graphics.DrawImage(bg, 0, 0);
                        graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                        graphics.DrawText(cardData.Name, 42, 345, 655, 650, 200);

                        graphics.DrawText(cardData.Website, 16, 375, 883, 650, 50, fontStyle: FontStyle.Bold);
                        graphics.DrawText(cardData.Email, 16, 375, 919, 650, 50, fontStyle: FontStyle.Bold);
                        graphics.DrawText(cardData.Phone, 16, 375, 951, 650, 50, fontStyle: FontStyle.Bold);
                        graphics.DrawText(cardData.Address, 16, 375, 1005, 650, 80, fontStyle: FontStyle.Bold);

                        var photos = cardData?.Data?.Photos ?? new List <PhotoInfo>();
                        for (var i = 0; i < photos.Count && i < 4; i++)
                        {
                            var img = GraphicsExt.LoadImg(photos[i].ImageUrl);

                            if (i == 0)
                            {
                                graphics.DrawImage(img, 1009, 595, 522, 307);
                            }
                            else
                            {
                                graphics.DrawImage(img, 1009 + (i - 1) * (150 + 36), 936, 150, 100);
                            }
                        }

                        var dicts = (cardData?.BaseDictionaries ?? new List <BaseDictionary>())
                                    .Where(x => DictData.ContainsKey(x.DictionaryID))
                                    .Select(x => DictData[x.DictionaryID])
                                    .ToList();

                        var countInRow = 3;
                        {
                            var infrastructures = dicts.Where(x =>
                                                              x.ParentId == SharedUseInfrastructureId || x.ParentId == SocialInfrastructureId)
                                                  .ToList();

                            for (var i = 0; i < infrastructures.Count && i < 6; i++)
                            {
                                var cell = (Math.Abs(i * countInRow) + i) % countInRow;
                                var row  = i / countInRow;

                                var el      = infrastructures[i];
                                var impPath = string.Join(Path.DirectorySeparatorChar.ToString(),
                                                          new[]
                                {
                                    "Resource", "Img", "infrastructure_icons", $"{el.Name.Replace(" ", "_")}.png"
                                });

                                if (!File.Exists(impPath))
                                {
                                    Console.WriteLine("Не найден файл инфраструктуры");
                                    break;
                                }

                                using (var img = Image.FromFile(impPath))
                                {
                                    graphics.DrawImage(img, 1005 + cell * (176), 1160 + row * (110));
                                }
                            }
                        }
                        {
                            var specialization = dicts.Where(x => x.ParentId == SpecializationId).ToList();
                            for (var i = 0; i < specialization.Count && i < 5; i++)
                            {
                                var el = specialization[i];
                                graphics.DrawText(el.Name, 11, 644, 1176 + i * (28), 200, 30,
                                                  Color.FromArgb(130, 130, 130));
                            }
                        }
                        {
                            var services = dicts.Where(x => x.ParentId == ServicesForResidentsId).OrderBy(x => x.Id)
                                           .ToList();
                            for (var i = 0; i < services.Count && i < 5; i++)
                            {
                                if (i == 0)
                                {
                                    graphics.DrawText("Сервисы", 18, 1005, 1430, 200, 30);
                                }

                                var el = services[i];
                                graphics.DrawText("• " + el.Name, 16, 1005, 1469 + i * (25), 600, 30);
                            }
                        }
                        if (tp == InnoTypes.Coworking)
                        {
                            var info = await GetFormatspacesAsync(cardBase.Id);

                            if (info == null)
                            {
                                return(null);
                            }

                            var spaces = info
                                         .Where(x => !string.IsNullOrWhiteSpace(x.Name) && !string.IsNullOrWhiteSpace(x.ImgUrl))
                                         .OrderBy(x => x.Name.ToLower())
                                         .GroupBy(x =>
                                                  (x.Name.IndexOf("(") != -1 ? x.Name.Substring(0, x.Name.IndexOf("(")) : x.Name)
                                                  .ToLower())
                                         .Select(x => x.First())
                                         .ToList();

                            for (var i = 0; i < spaces.Count && i < 2; i++)
                            {
                                var sp  = spaces[i];
                                var img = GraphicsExt.LoadImg(sp.ImgUrl);

                                var xStart = 343 + i * (240 + 27);
                                graphics.DrawImage(img, xStart, 1182, 240, 156);

                                SolidBrush blueBrush = new SolidBrush(Color.FromArgb(227, 227, 227));
                                graphics.FillRectangle(blueBrush, new Rectangle(xStart, 1337, 240, 34));

                                graphics.DrawText(sp.Name.ToUpper(), 11, xStart + 10, 1345, 240, 34,
                                                  Color.FromArgb(24, 62, 73), FontStyle.Bold);

                                if (string.IsNullOrWhiteSpace(sp.Price))
                                {
                                    continue;
                                }

                                graphics.DrawText("Стоимость (руб.)", 18, xStart, 1388, 240, 50);
                                graphics.DrawText(sp.Price, 24, xStart, 1421, 240, 50, Color.FromArgb(245, 152, 45));
                            }
                        }
                    }

                    if (!Directory.Exists("cards"))
                    {
                        Directory.CreateDirectory("cards");
                    }

                    bg.Save(string.Join(Path.DirectorySeparatorChar.ToString(),
                                        new[] { "cards", $"{cardData.Id}.png" }));
                }

                return(cardData);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }

            return(null);
        }