Exemple #1
0
        void populate_tiles()
        {
            List <Library> libraries = new List <Library>();

            libraries.AddRange(Session.Libraries);
            libraries.Add(Session.Project.Library);

            List <string> sets = new List <string>();

            switch (Session.Preferences.TileView)
            {
            case TileView.Library:
            {
                foreach (Library lib in libraries)
                {
                    if (!fTileSets[lib.ID])
                    {
                        continue;
                    }

                    if (!sets.Contains(lib.Name))
                    {
                        sets.Add(lib.Name);
                    }
                }

                sets.Sort();
            }
            break;

            case TileView.Size:
            {
                List <int> areas = new List <int>();
                foreach (Library lib in libraries)
                {
                    foreach (Tile t in lib.Tiles)
                    {
                        if (!areas.Contains(t.Area))
                        {
                            areas.Add(t.Area);
                        }
                    }
                }

                areas.Sort();

                foreach (int area in areas)
                {
                    sets.Add("Size: " + area);
                }
            }
            break;

            case TileView.Category:
            {
                foreach (TileCategory cat in Enum.GetValues(typeof(TileCategory)))
                {
                    sets.Add(cat.ToString());
                }
            }
            break;
            }

            int size = 32;

            switch (Session.Preferences.TileSize)
            {
            case TileSize.Small:
                size = 16;
                break;

            case TileSize.Medium:
                size = 32;
                break;

            case TileSize.Large:
                size = 64;
                break;
            }

            TileList.BeginUpdate();

            TileList.Groups.Clear();
            foreach (string set in sets)
            {
                TileList.Groups.Add(set, set);
            }

            TileList.ShowGroups = (TileList.Groups.Count != 0);

            List <ListViewItem> item_list  = new List <ListViewItem>();
            List <Image>        image_list = new List <Image>();

            foreach (Library lib in libraries)
            {
                if (!fTileSets[lib.ID])
                {
                    continue;
                }

                foreach (Tile t in lib.Tiles)
                {
                    if (!match(t, SearchBox.Text))
                    {
                        continue;
                    }

                    ListViewItem lvi = new ListViewItem(t.ToString());
                    lvi.Tag = t;

                    switch (Session.Preferences.TileView)
                    {
                    case TileView.Library:
                        lvi.Group = TileList.Groups[lib.Name];
                        break;

                    case TileView.Size:
                        lvi.Group = TileList.Groups["Size: " + t.Area];
                        break;

                    case TileView.Category:
                        lvi.Group = TileList.Groups[t.Category.ToString()];
                        break;
                    }

                    // Get tile image
                    Image img = (t.Image != null) ? t.Image : t.BlankImage;
                    if (img == null)
                    {
                        continue;
                    }

                    try
                    {
                        Bitmap bmp = new Bitmap(size, size);
                        if (t.Size.Width > t.Size.Height)
                        {
                            int       height = (t.Size.Height * size) / t.Size.Width;
                            Rectangle rect   = new Rectangle(0, (size - height) / 2, size, height);

                            Graphics g = Graphics.FromImage(bmp);
                            g.DrawImage(img, rect);
                        }
                        else
                        {
                            int       width = (t.Size.Width * size) / t.Size.Height;
                            Rectangle rect  = new Rectangle((size - width) / 2, 0, width, size);

                            Graphics g = Graphics.FromImage(bmp);
                            g.DrawImage(img, rect);
                        }

                        image_list.Add(bmp);
                        lvi.ImageIndex = image_list.Count - 1;

                        item_list.Add(lvi);
                    }
                    catch (Exception ex)
                    {
                        LogSystem.Trace(ex);
                    }
                }
            }

            TileList.LargeImageList            = new ImageList();
            TileList.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;
            TileList.LargeImageList.ImageSize  = new Size(size, size);
            TileList.LargeImageList.Images.AddRange(image_list.ToArray());

            TileList.Items.Clear();
            TileList.Items.AddRange(item_list.ToArray());

            if (TileList.Items.Count == 0)
            {
                ListViewItem lvi = TileList.Items.Add("(no tiles)");
                lvi.ForeColor = SystemColors.GrayText;
            }

            TileList.EndUpdate();
        }
        void update_tiles()
        {
            List <Tile> tiles = new List <Tile>();

            foreach (Library lib in Session.Libraries)
            {
                foreach (Tile t in lib.Tiles)
                {
                    if (fMatchCategory)
                    {
                        if (fCategory != t.Category)
                        {
                            continue;
                        }
                    }

                    bool same_size = false;

                    if (fTileSize != Size.Empty)
                    {
                        if ((t.Size.Width == fTileSize.Width) && (t.Size.Height == fTileSize.Height))
                        {
                            same_size = true;
                        }

                        if ((t.Size.Width == fTileSize.Height) && (t.Size.Height == fTileSize.Width))
                        {
                            same_size = true;
                        }
                    }
                    else
                    {
                        same_size = true;
                    }

                    if (same_size)
                    {
                        tiles.Add(t);
                    }
                }
            }

            TileList.Groups.Clear();
            switch (fGroupBy)
            {
            case GroupBy.Library:
            {
                foreach (Library lib in Session.Libraries)
                {
                    TileList.Groups.Add(lib.Name, lib.Name);
                }
            }
            break;

            case GroupBy.Category:
            {
                Array cats = Enum.GetValues(typeof(TileCategory));
                foreach (TileCategory cat in cats)
                {
                    TileList.Groups.Add(cat.ToString(), cat.ToString());
                }
            }
            break;
            }

            TileList.BeginUpdate();

            TileList.LargeImageList            = new ImageList();
            TileList.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;
            TileList.LargeImageList.ImageSize  = new Size(64, 64);

            List <ListViewItem> item_list = new List <ListViewItem>();

            foreach (Tile t in tiles)
            {
                ListViewItem lvi = new ListViewItem(t.ToString());
                lvi.Tag = t;

                switch (fGroupBy)
                {
                case GroupBy.Library:
                {
                    Library lib = Session.FindLibrary(t);
                    lvi.Group = TileList.Groups[lib.Name];
                }
                break;

                case GroupBy.Category:
                {
                    lvi.Group = TileList.Groups[t.Category.ToString()];
                }
                break;
                }

                // Get tile image
                Image img = t.Image != null ? t.Image : t.BlankImage;

                Bitmap bmp = new Bitmap(64, 64);
                if (t.Size.Width > t.Size.Height)
                {
                    int       height = (t.Size.Height * 64) / t.Size.Width;
                    Rectangle rect   = new Rectangle(0, (64 - height) / 2, 64, height);

                    Graphics g = Graphics.FromImage(bmp);
                    g.DrawImage(img, rect);
                }
                else
                {
                    int       width = (t.Size.Width * 64) / t.Size.Height;
                    Rectangle rect  = new Rectangle((64 - width) / 2, 0, width, 64);

                    Graphics g = Graphics.FromImage(bmp);
                    g.DrawImage(img, rect);
                }

                TileList.LargeImageList.Images.Add(bmp);
                lvi.ImageIndex = TileList.LargeImageList.Images.Count - 1;

                item_list.Add(lvi);
            }

            TileList.Items.Clear();
            TileList.Items.AddRange(item_list.ToArray());

            TileList.EndUpdate();
        }