Beispiel #1
0
        public SKBitmap A(List <Section> sections, Dictionary <Section, BitmapData> bitmaps)
        {
            int width  = 0;
            int height = 250;

            bitmaps.Values.ToList().ForEach(b =>
            {
                if (b.Width > width)
                {
                    width = b.Width;
                }

                height += b.Height;
            });

            var merge = new SKBitmap(width, height);

            using (var c = new SKCanvas(merge))
            {
                int y = 0;

                using (var paint = new SKPaint
                {
                    IsAntialias = true,
                    FilterQuality = SKFilterQuality.High,
                    Color = SKColor.Parse("#e7accb")//new SKColor(40, 40, 40)
                }) c.DrawRect(0, 0, merge.Width, merge.Height, paint);

                sections.ToList().ForEach(section =>
                {
                    var bitmapData = bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value;

                    using (var bitmap = LoadFromCache(bitmapData))
                    {
                        c.DrawBitmap(bitmap, 0, y);
                        y += bitmap.Height;
                    }

                    GC.Collect();
                    ;
                });

                using (var textPaint = new SKPaint
                {
                    IsAntialias = true,
                    FilterQuality = SKFilterQuality.High,
                    TextSize = (int)(ChicRatios.Get1024(150) * EntryHeight),
                    Color = SKColors.White,
                    Typeface = ChicTypefaces.BurbankBigRegularBlack,
                    ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
                })
                {
                    var sacText   = "Code 'Chic'\n#Ad";
                    int textWidth = (int)textPaint.MeasureText(sacText);

                    int left   = (merge.Width - textWidth) / 2;
                    int top    = merge.Height - (int)(ChicRatios.Get1024(150) * EntryHeight * 2);
                    int right  = left + textWidth;
                    int bottom = merge.Height - (int)(ChicRatios.Get1024(150) * EntryHeight);

                    ChicText.DrawMultilineText(c, sacText, new SKRect(left, top, right, bottom), textPaint);

                    sacText = "";
                }

                using (var shadow = new SKPaint
                {
                    IsAntialias = true,
                    FilterQuality = SKFilterQuality.High,
                    ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
                })
                {
                    using (var heart = SKBitmap.Decode($"{Root}Resources/heartTopLeft.png"))
                    {
                        c.DrawBitmap(heart, 0, 0, shadow);
                    }

                    using (var hearts = SKBitmap.Decode($"{Root}Resources/heartsBottomRight.png"))
                    {
                        c.DrawBitmap(hearts, merge.Width - hearts.Width, merge.Height - hearts.Height, shadow);
                    }
                }
            }

            sections = null;
            bitmaps  = null;

            return(merge);
        }
Beispiel #2
0
        /*public SKBitmap B(List<Section> sections, Dictionary<Section, SKBitmap> bitmaps)
         * {
         *  List<int> featured = new List<int>();
         *  List<int> others = new List<int>();
         *
         *  int featuredCount = 0;
         *
         *  foreach (var section in sections)
         *  {
         *      if (section.SectionId.Contains("Featured"))
         *      {
         *          featured.Add(bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value.Width);
         *          featuredCount++;
         *          continue;
         *      }
         *      else //if (section.SectionId.Contains("Daily"))
         *      {
         *          others.Add(bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value.Width);
         *          continue;
         *      }
         *  };
         *
         *  int columnCount = featured.Count > 0 ? 2 : 1;
         *
         *  int width = columnCount * featured.Max();
         *  int featuredHeight = 0;
         *  int othersHeight = 0;
         *
         *  bitmaps.ToList().ForEach(pair =>
         *  {
         *      if (pair.Key.SectionId.Contains("Featured")) featuredHeight += pair.Value.Height;
         *      else othersHeight += pair.Value.Height;
         *  });
         *
         *  int height = Math.Max(featuredHeight, othersHeight) + 250;
         *
         *  int ratio = 0;
         *
         *  int fullHeight = 0;
         *  int fullWidth = 0;
         *
         *  if (height >= width) ratio = height / 9;
         *  else ratio = width / 16;
         *
         *  fullHeight = ratio * 9;
         *  fullWidth = ratio * 16;
         *
         *  var full = new SKBitmap(fullWidth, fullHeight);
         *
         *  using (var merge = new SKBitmap(width, height))
         *  {
         *      using (var c = new SKCanvas(merge))
         *      {
         *          int y = 0;
         *          int x = 0;
         *          int i = 0;
         *
         *          sections.ToList().ForEach(section =>
         *          {
         *              var bitmap = bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value;
         *
         *              c.DrawBitmap(bitmap, x, y);
         *              y += bitmap.Height;
         *              i++;
         *
         *              if (i == featuredCount)
         *              {
         *                  y = 0;
         *                  x += width / columnCount;
         *              }
         *          });
         *      }
         *
         *      using (var c = new SKCanvas(full))
         *      {
         *          c.DrawRect(0, 0, full.Width, full.Height,
         *              new SKPaint
         *              {
         *                  IsAntialias = true,
         *                  FilterQuality = SKFilterQuality.High,
         *                  Color = new SKColor(40, 40, 40)
         *              });
         *
         *          c.DrawBitmap(merge, (full.Width - merge.Width) / 2, 0,
         *              new SKPaint
         *              {
         *                  IsAntialias = true,
         *                  FilterQuality = SKFilterQuality.High
         *              });
         *
         *          var textPaint = new SKPaint
         *          {
         *              IsAntialias = true,
         *              FilterQuality = SKFilterQuality.High,
         *              TextSize = 200,
         *              Color = SKColors.White,
         *              Typeface = ChicTypefaces.BurbankBigRegularBlack,
         *              ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
         *          };
         *
         *          var sacText = "Code 'Chic' #Ad";
         *
         *          c.DrawText(sacText, (full.Width - textPaint.MeasureText(sacText)) / 2,
         *              full.Height - 50, textPaint);
         *      }
         *
         *      return full;
         *  }
         * }*/

        public Dictionary <Section, BitmapData> GenerateSections(Dictionary <StorefrontEntry, BitmapData> entries)
        {
            int maxEntriesPerRow = 6;

            Dictionary <Section, BitmapData> sectionsBitmaps = new Dictionary <Section, BitmapData>();

            var content = FortniteContent.Get();

            List <Section> sections = new List <Section>();

            entries.Keys.ToList().ForEach(key =>
            {
                if (!sections.Contains(x => x.SectionId == key.SectionId))
                {
                    if (content.ShopSections.Contains(key.SectionId))
                    {
                        sections.Add(content.ShopSections.Get(key.SectionId));
                    }
                    else
                    {
                        sections.Add(new Section
                        {
                            SectionId       = key.SectionId,
                            DisplayName     = "",
                            LandingPriority = 49
                        });
                    }
                }
            });

            List <int> entriesCount = new List <int>();

            sections.ForEach(section =>
            {
                int count = 0;

                entries.ToList().ForEach(entry =>
                {
                    if (entry.Key.SectionId == section.SectionId)
                    {
                        count++;
                    }
                });

                entriesCount.Add(count);
            });

            maxEntriesPerRow = Math.Clamp(entriesCount.Max(), 0, maxEntriesPerRow);

            int th = (int)(ChicRatios.Get1024(200) * EntryHeight);
            int hf = (int)(ChicRatios.Get1024(150) * EntryHeight);
            int h  = (int)(ChicRatios.Get1024(100) * EntryHeight);
            int f  = (int)(ChicRatios.Get1024(50) * EntryHeight);

            foreach (var section in sections)
            {
                Dictionary <StorefrontEntry, BitmapData> se = new Dictionary <StorefrontEntry, BitmapData>();

                entries.ToList().ForEach(entry =>
                {
                    if (entry.Key.SectionId == section.SectionId)
                    {
                        se.Add(entry);
                    }
                });

                Dictionary <StorefrontEntry, BitmapData> sectionEntries = new Dictionary <StorefrontEntry, BitmapData>();
                sectionEntries.Add(se.ToList().Sort(EntryComparer.Comparer, 0));

                int extraHeight = section.HasName ? th : 0;

                SKBitmap bitmap = new SKBitmap(h /*150*/ + maxEntriesPerRow * (EntryWidth + h /*+ 50*/), extraHeight + (int)Math.Ceiling((decimal)sectionEntries.Count / maxEntriesPerRow) * (EntryHeight + h /*+ 50*/));

                using (SKCanvas c = new SKCanvas(bitmap))
                {
                    using (var paint = new SKPaint
                    {
                        IsAntialias = true,
                        FilterQuality = SKFilterQuality.High,
                        Color = SKColor.Parse("#e7accb")//new SKColor(40, 40, 40)
                    }) c.DrawRect(0, 0, bitmap.Width, bitmap.Height, paint);

                    int x      = f;//100;
                    int y      = extraHeight;
                    int row    = 0;
                    int column = 0;

                    for (int i = 0; i < sectionEntries.Count; i++)
                    {
                        var entry = sectionEntries.ToList()[i];

                        using (var b = LoadFromCache(entry.Value))
                        {
                            using (var paint = new SKPaint {
                                IsAntialias = true, FilterQuality = SKFilterQuality.High
                            })
                                c.DrawBitmap(b, x, y, paint);
                        }

                        GC.Collect();

                        if (++column == maxEntriesPerRow)
                        {
                            row++;
                            column = 0;
                            //x = 50;//100;
                        }

                        x = f + (EntryWidth + h) * column; /*+ 50*/
                        y = extraHeight + (EntryHeight + h /*+ 50*/) * row;
                    }

                    using (var paint = new SKPaint
                    {
                        IsAntialias = true,
                        FilterQuality = SKFilterQuality.High,
                        Color = SKColors.White,
                        TextSize = h,
                        Typeface = ChicTypefaces.BurbankBigRegularBlack,
                        TextAlign = SKTextAlign.Left,
                        ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
                    }) if (section.HasName)
                        {
                            c.DrawText(section.DisplayName, h, hf, paint);
                        }
                }

                sectionEntries = null;

                sectionsBitmaps.Add(section, SaveToCache(bitmap, "section_" + section.SectionId));
            }

            content  = null;
            sections = null;
            entries  = null;

            GC.Collect();

            return(sectionsBitmaps);
        }
Beispiel #3
0
        public List <BitmapData> DrawSections(ShopV2 shop)
        {
            int maxEntriesPerRow = 6;
            var result           = new List <BitmapData>();

            maxEntriesPerRow = Math.Clamp(shop.Sections.Max(x => x.Value.Count), 0, maxEntriesPerRow);

            int th = (int)(ChicRatios.Get1024(200) * EntryHeight);
            int hf = (int)(ChicRatios.Get1024(150) * EntryHeight);
            int h  = (int)(ChicRatios.Get1024(100) * EntryHeight);
            int f  = (int)(ChicRatios.Get1024(50) * EntryHeight);

            int width = h + maxEntriesPerRow * (EntryWidth + h);

            foreach (var section in shop.Sections)
            {
                var sectionInfo = shop.SectionInfos.Find(x => x.SectionId == section.Key);
                int extraHeight = sectionInfo.HasName ? th : 0;
                int height      = extraHeight + (int)Math.Ceiling((decimal)section.Value.Count / maxEntriesPerRow) * (EntryHeight + h);

                using (SKBitmap bitmap = new SKBitmap(width, height))
                {
                    using (SKCanvas c = new SKCanvas(bitmap))
                    {
                        using (var paint = new SKPaint
                        {
                            IsAntialias = true,
                            FilterQuality = SKFilterQuality.High,
                            Color = SKColor.Parse("#e7accb")//new SKColor(40, 40, 40)
                        }) c.DrawRect(0, 0, width, height, paint);

                        int x      = f;//100;
                        int y      = extraHeight;
                        int row    = 0;
                        int column = 0;

                        for (int i = 0; i < section.Value.Count; i++)
                        {
                            var entry = section.Value[i];

                            using (var b = DrawEntry(entry) /*LoadFromCache(entry.CacheId)*/)
                            {
                                using (var paint = new SKPaint {
                                    IsAntialias = true, FilterQuality = SKFilterQuality.High
                                })
                                    c.DrawBitmap(b, x, y, paint);
                            }

                            GC.Collect();

                            if (++column == maxEntriesPerRow)
                            {
                                row++;
                                column = 0;
                                //x = 50;//100;
                            }

                            x = f + (EntryWidth + h) * column; /*+ 50*/
                            y = extraHeight + (EntryHeight + h /*+ 50*/) * row;
                        }

                        using (var paint = new SKPaint
                        {
                            IsAntialias = true,
                            FilterQuality = SKFilterQuality.High,
                            Color = SKColors.White,
                            TextSize = h,
                            Typeface = ChicTypefaces.BurbankBigRegularBlack,
                            TextAlign = SKTextAlign.Left,
                            ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
                        }) if (sectionInfo.HasName)
                            {
                                c.DrawText(sectionInfo.DisplayName, h, hf, paint);
                            }
                    }

                    result.Add(SaveToCache(bitmap, section.Key));
                }
            }

            return(result);
        }