Ejemplo n.º 1
0
        private void LoadTile(int[] tile)
        {
            var       x = tile[0];
            var       y = tile[1];
            string    _SelectedMapName = _map;
            Rectangle rect             = new Rectangle();

            rect.Name                = _SelectedMapName.Replace("'", string.Empty).Replace(" ", string.Empty) + "_" + x.ToString("D2") + "_" + y.ToString("D2"); //leading zeros just like adts (TODO: NOT REALLY), this breaks when the mapname has special characters (zg)D:
            rect.Width               = WDTGrid.Width / 64;
            rect.Height              = WDTGrid.Height / 64;
            rect.VerticalAlignment   = VerticalAlignment.Top;
            rect.HorizontalAlignment = HorizontalAlignment.Left;
            rect.MouseEnter         += Rect_MouseEnter;
            rect.MouseLeave         += Rect_MouseLeave;
            if (CASC.cascHandler.FileExists(System.IO.Path.Combine(@"world\minimaps\" + _SelectedMapName + "\\map" + x.ToString("D2") + "_" + y.ToString("D2") + ".blp")))
            {
                rect.MouseLeftButtonDown += new MouseButtonEventHandler(Rectangle_Mousedown);
                var xmargin = (x * rect.Width) - (min_x * rect.Width);
                var ymargin = (y * rect.Height) - (min_y * rect.Height);
                rect.Margin = new Thickness(xmargin, ymargin, 0, 0);

                var blp = new BLPReader();
                blp.LoadBLP(@"world\minimaps\" + _SelectedMapName + "\\map" + x.ToString("D2") + "_" + y.ToString("D2") + ".blp");
                BitmapImage bitmapImage = new BitmapImage();

                using (MemoryStream bitmap = blp.asBitmapStream())
                {
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource      = bitmap;
                    bitmapImage.DecodePixelHeight = Convert.ToInt32(rect.Width);
                    bitmapImage.DecodePixelWidth  = Convert.ToInt32(rect.Height);
                    bitmapImage.CacheOption       = BitmapCacheOption.OnLoad;
                    bitmapImage.EndInit();
                }

                ImageBrush imgBrush = new ImageBrush(bitmapImage);
                rect.Fill = imgBrush;
            }
            else
            {
                var xmargin = (x * rect.Width) - (min_x * rect.Width);
                var ymargin = (y * rect.Height) - (min_y * rect.Height);
                rect.Margin = new Thickness(xmargin, ymargin, 0, 0);
                rect.Fill   = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            }
            WDTGrid.Children.Add(rect);
        }
Ejemplo n.º 2
0
        private void LoadTile(string basedir, int[] tile)
        {
            var       x = tile[0];
            var       y = tile[1];
            string    _SelectedMapName = ((KeyValuePair <int, string>)MapListBox.SelectedValue).Value;
            Rectangle rect             = new Rectangle();

            rect.Name                = _SelectedMapName.Replace("'", string.Empty).Replace(" ", string.Empty) + x.ToString("D2") + "_" + y.ToString("D2"); //leading zeros just like adts, this breaks when the mapname has special characters (zg)D:
            rect.Width               = WDTGrid.Width / 64;
            rect.Height              = WDTGrid.Height / 64;
            rect.VerticalAlignment   = VerticalAlignment.Top;
            rect.HorizontalAlignment = HorizontalAlignment.Left;

            if (File.Exists(basedir + "World\\Minimaps\\" + _SelectedMapName + "\\map" + x.ToString("D2") + "_" + y.ToString("D2") + ".blp"))
            {
                rect.MouseLeftButtonDown += new MouseButtonEventHandler(Rectangle_Mousedown);
                var xmargin = x * rect.Width;
                var ymargin = y * rect.Height;
                rect.Margin = new Thickness(xmargin, ymargin, 0, 0);
                var blp = new BLPReader(basedir);

                //Kalimdor takes a few seconds to load, and takes up about ~4xxMB of memory after its loaded, this can be much improved
                blp.LoadBLP("World\\Minimaps\\" + _SelectedMapName + "\\map" + x.ToString("D2") + "_" + y.ToString("D2") + ".blp");
                BitmapImage bitmapImage = new BitmapImage();
                using (MemoryStream bitmap = blp.asBitmapStream())
                {
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource      = bitmap;
                    bitmapImage.DecodePixelHeight = Convert.ToInt32(rect.Width);
                    bitmapImage.DecodePixelWidth  = Convert.ToInt32(rect.Height);
                    bitmapImage.CacheOption       = BitmapCacheOption.OnLoad;
                    bitmapImage.EndInit();
                }
                ImageBrush imgBrush = new ImageBrush(bitmapImage);
                rect.Fill = imgBrush;
            }
            else
            {
                rect.Fill = new SolidColorBrush(Color.FromRgb(0, 111, 0));
                Console.WriteLine(basedir + "World\\Minimaps\\" + _SelectedMapName + "\\map" + x.ToString("D2") + "_" + y.ToString("D2") + ".blp");
            }
            WDTGrid.Children.Add(rect);
        }