Exemple #1
0
        private void update_tiles()
        {
            List <Masterplan.Data.Tile> tiles = new List <Masterplan.Data.Tile>();

            foreach (Library library in Session.Libraries)
            {
                foreach (Masterplan.Data.Tile tile in library.Tiles)
                {
                    if (this.fMatchCategory && this.fCategory != tile.Category)
                    {
                        continue;
                    }
                    bool flag = false;
                    if (this.fTileSize == System.Drawing.Size.Empty)
                    {
                        flag = true;
                    }
                    else
                    {
                        if (tile.Size.Width == this.fTileSize.Width && tile.Size.Height == this.fTileSize.Height)
                        {
                            flag = true;
                        }
                        if (tile.Size.Width == this.fTileSize.Height && tile.Size.Height == this.fTileSize.Width)
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        continue;
                    }
                    tiles.Add(tile);
                }
            }
            this.TileList.Groups.Clear();
            switch (this.fGroupBy)
            {
            case TileSelectForm.GroupBy.Library:
            {
                List <Library> .Enumerator enumerator = Session.Libraries.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        Library current = enumerator.Current;
                        this.TileList.Groups.Add(current.Name, current.Name);
                    }
                    break;
                }
                finally
                {
                    ((IDisposable)enumerator).Dispose();
                }
            }

            case TileSelectForm.GroupBy.Category:
            {
                IEnumerator enumerator1 = Enum.GetValues(typeof(TileCategory)).GetEnumerator();
                try
                {
                    while (enumerator1.MoveNext())
                    {
                        TileCategory tileCategory = (TileCategory)enumerator1.Current;
                        this.TileList.Groups.Add(tileCategory.ToString(), tileCategory.ToString());
                    }
                    break;
                }
                finally
                {
                    IDisposable disposable = enumerator1 as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            }
            this.TileList.BeginUpdate();
            this.TileList.LargeImageList = new ImageList()
            {
                ColorDepth = ColorDepth.Depth32Bit,
                ImageSize  = new System.Drawing.Size(64, 64)
            };
            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (Masterplan.Data.Tile tile1 in tiles)
            {
                ListViewItem listViewItem = new ListViewItem(tile1.ToString())
                {
                    Tag = tile1
                };
                switch (this.fGroupBy)
                {
                case TileSelectForm.GroupBy.Library:
                {
                    Library library1 = Session.FindLibrary(tile1);
                    listViewItem.Group = this.TileList.Groups[library1.Name];
                    break;
                }

                case TileSelectForm.GroupBy.Category:
                {
                    listViewItem.Group = this.TileList.Groups[tile1.Category.ToString()];
                    break;
                }
                }
                Image  image  = (tile1.Image != null ? tile1.Image : tile1.BlankImage);
                Bitmap bitmap = new Bitmap(64, 64);
                if (tile1.Size.Width <= tile1.Size.Height)
                {
                    System.Drawing.Size size  = tile1.Size;
                    System.Drawing.Size size1 = tile1.Size;
                    int       width           = size.Width * 64 / size1.Height;
                    Rectangle rectangle       = new Rectangle((64 - width) / 2, 0, width, 64);
                    Graphics.FromImage(bitmap).DrawImage(image, rectangle);
                }
                else
                {
                    System.Drawing.Size size2 = tile1.Size;
                    System.Drawing.Size size3 = tile1.Size;
                    int       height          = size2.Height * 64 / size3.Width;
                    Rectangle rectangle1      = new Rectangle(0, (64 - height) / 2, 64, height);
                    Graphics.FromImage(bitmap).DrawImage(image, rectangle1);
                }
                this.TileList.LargeImageList.Images.Add(bitmap);
                listViewItem.ImageIndex = this.TileList.LargeImageList.Images.Count - 1;
                listViewItems.Add(listViewItem);
            }
            this.TileList.Items.Clear();
            this.TileList.Items.AddRange(listViewItems.ToArray());
            this.TileList.EndUpdate();
        }