예제 #1
0
        public void UpdateMainWindowIcons(double margin)
        {
            // adapter.query below caused unhandled exception with main.selectedID as 0.
            if (adapter == null || main.selectedID == 0)
            {
                return;
            }

            // Convert to background worker here

            DataRow res           = adapter.Query(string.Format("SELECT `SpellIconID`,`ActiveIconID` FROM `{0}` WHERE `ID` = '{1}'", "spell", main.selectedID)).Rows[0];
            uint    iconInt       = uint.Parse(res[0].ToString());
            uint    iconActiveInt = uint.Parse(res[1].ToString());

            // Update currently selected icon, we don't currently use ActiveIconID
            using (FileStream fileStream = new FileStream(GetIconPath(iconInt) + ".blp", FileMode.Open))
            {
                using (BlpFile image = new BlpFile(fileStream))
                {
                    using (var bit = image.getBitmap(0))
                    {
                        System.Windows.Controls.Image temp = new System.Windows.Controls.Image();

                        temp.Width               = iconSize == null ? 32 : iconSize.Value;
                        temp.Height              = iconSize == null ? 32 : iconSize.Value;
                        temp.Margin              = iconMargin == null ? new Thickness(margin, 0, 0, 0) : iconMargin.Value;
                        temp.VerticalAlignment   = VerticalAlignment.Top;
                        temp.HorizontalAlignment = HorizontalAlignment.Left;
                        temp.Source              = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                            bit.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
                            BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
                        temp.Name = "CurrentSpellIcon";

                        // Code smells here on hacky positioning and updating the icon
                        temp.Margin = new Thickness(103, 38, 0, 0);
                        main.CurrentIconGrid.Children.Clear();
                        main.CurrentIconGrid.Children.Add(temp);
                    }
                }
            }

            // Load all icons available if have not already
            if (!loadedAllIcons)
            {
                var watch = new Stopwatch();
                watch.Start();
                LoadAllIcons(margin);
                watch.Stop();
                Console.WriteLine($"Loaded all icons as UI elements in {watch.ElapsedMilliseconds}ms");
            }
        }
예제 #2
0
        public void LoadAllIcons(double margin)
        {
            loadedAllIcons = true;
            List <Icon_DBC_Lookup> lookups = Lookups.ToList();

            foreach (var entry in lookups)
            {
                var path = entry.Name;
                if (!File.Exists(path + ".blp"))
                {
                    Console.WriteLine("Warning: Icon not found: " + path + ".blp");
                    continue;
                }
                bool   loaded = false;
                Bitmap bit    = null;
                try
                {
                    using (FileStream fileStream = new FileStream(path + ".blp", FileMode.Open))
                    {
                        using (BlpFile image = new BlpFile(fileStream))
                        {
                            bit    = image.getBitmap(0);
                            loaded = true;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error loading image, unsupported BLP format: {path}.blp\n{e.Message}\n{e}");
                }
                if (!loaded)
                {
                    continue;
                }

                System.Windows.Controls.Image temp = new System.Windows.Controls.Image();
                temp.Width               = iconSize == null ? 32 : iconSize.Value;
                temp.Height              = iconSize == null ? 32 : iconSize.Value;
                temp.Margin              = iconMargin == null ? new Thickness(margin, 0, 0, 0) : iconMargin.Value;
                temp.VerticalAlignment   = VerticalAlignment.Top;
                temp.HorizontalAlignment = HorizontalAlignment.Left;
                temp.Source              = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bit.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
                temp.Name       = "Index_" + entry.Offset;
                temp.ToolTip    = path;
                temp.MouseDown += ImageDown;

                main.IconGrid.Children.Add(temp);
                bit.Dispose();
            }
        }
예제 #3
0
        public async void UpdateMainWindowIcons(double margin)
        {
            if (adapter == null || main.selectedID == 0)               // adapter.query below caused unhandled exception with main.selectedID as 0.
            {
                return;
            }

            DataRow res;

            try
            {
                res = adapter.query(string.Format("SELECT `SpellIconID`,`ActiveIconID` FROM `{0}` WHERE `ID` = '{1}'", adapter.Table, main.selectedID)).Rows[0];
            }
            catch (Exception)
            {
                return;
            }
            UInt32 iconInt        = UInt32.Parse(res[0].ToString());
            UInt32 iconActiveInt  = UInt32.Parse(res[1].ToString());
            UInt32 selectedRecord = UInt32.MaxValue;

            for (UInt32 i = 0; i < header.RecordCount; ++i)
            {
                if (body.records[i].ID == iconInt)
                {
                    selectedRecord = i;

                    break;
                }

                if (body.records[i].ID == iconActiveInt)
                {
                    selectedRecord = i;

                    break;
                }
            }

            string icon = "";

            int offset = 0;

            try
            {
                if (selectedRecord == UInt32.MaxValue)
                {
                    throw new Exception("The icon for this spell does not exist in the SpellIcon.dbc");
                }

                offset = (int)body.records[selectedRecord].Name;

                while (body.StringBlock[offset] != '\0')
                {
                    icon += body.StringBlock[offset++];
                }

                if (!File.Exists(icon + ".blp"))
                {
                    throw new Exception("File could not be found: " + "Icons\\" + icon + ".blp");
                }
            }

            catch (Exception ex)
            {
                main.Dispatcher.Invoke(new Action(() => main.HandleErrorMessage(ex.Message)));

                return;
            }

            FileStream fileStream = new FileStream(icon + ".blp", FileMode.Open);

            SereniaBLPLib.BlpFile image;

            image = new SereniaBLPLib.BlpFile(fileStream);

            Bitmap bit = image.getBitmap(0);

            await Task.Factory.StartNew(() =>
            {
                main.CurrentIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bit.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
            }, CancellationToken.None, TaskCreationOptions.None, main.UIScheduler);

            image.close();
            fileStream.Close();

            if (!loadedAllIcons)
            {
                loadedAllIcons = true;

                int currentOffset = 1;

                string[] icons = body.StringBlock.Split('\0');

                int iconIndex   = 0;
                int columnsUsed = icons.Length / 11;
                int rowsToDo    = columnsUsed / 2;

                for (int j = -rowsToDo; j <= rowsToDo; ++j)
                {
                    for (int i = -5; i < 6; ++i)
                    {
                        ++iconIndex;
                        if (iconIndex >= icons.Length - 1)
                        {
                            break;
                        }
                        int this_icons_offset = currentOffset;

                        currentOffset += icons[iconIndex].Length + 1;

                        if (!File.Exists(icons[iconIndex] + ".blp"))
                        {
                            Console.WriteLine("Warning: Icon not found: " + icons[iconIndex] + ".blp");

                            continue;
                        }

                        bool loaded = false;
                        try
                        {
                            fileStream = new FileStream(icons[iconIndex] + ".blp", FileMode.Open);
                            image      = new BlpFile(fileStream);
                            bit        = image.getBitmap(0);
                            loaded     = true;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine($"Error loading image, unsupported BLP format: {icons[iconIndex]}.blp\n{e.Message}\n{e}");
                        }
                        if (!loaded)
                        {
                            image?.close();
                            fileStream?.Close();
                            continue;
                        }

                        await Task.Factory.StartNew(() =>
                        {
                            System.Windows.Controls.Image temp = new System.Windows.Controls.Image();

                            temp.Width               = iconSize == null ? 32 : iconSize.Value;
                            temp.Height              = iconSize == null ? 32 : iconSize.Value;
                            temp.Margin              = iconMargin == null ? new System.Windows.Thickness(margin, 0, 0, 0) : iconMargin.Value;
                            temp.VerticalAlignment   = VerticalAlignment.Top;
                            temp.HorizontalAlignment = HorizontalAlignment.Left;
                            temp.Source              = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bit.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
                            temp.Name       = "Index_" + this_icons_offset;
                            temp.ToolTip    = icons[iconIndex];
                            temp.MouseDown += this.ImageDown;

                            main.IconGrid.Children.Add(temp);
                        }, CancellationToken.None, TaskCreationOptions.None, main.UIScheduler);

                        image.close();
                        fileStream.Close();
                    }
                }
            }
        }
예제 #4
0
        public void UpdateMainWindowIcons(double margin)
        {
            // adapter.query below caused unhandled exception with main.selectedID as 0.
            if (adapter == null || main.selectedID == 0)
            {
                return;
            }

            DataRow res           = adapter.query(string.Format("SELECT `SpellIconID`,`ActiveIconID` FROM `{0}` WHERE `ID` = '{1}'", adapter.Table, main.selectedID)).Rows[0];
            uint    iconInt       = uint.Parse(res[0].ToString());
            uint    iconActiveInt = uint.Parse(res[1].ToString());

            // Update currently selected icon, we don't currently use ActiveIconID
            using (FileStream fileStream = new FileStream(GetIconPath(iconInt) + ".blp", FileMode.Open))
            {
                using (BlpFile image = new BlpFile(fileStream))
                {
                    Bitmap bit = image.getBitmap(0);
                    System.Windows.Controls.Image temp = new System.Windows.Controls.Image();

                    temp.Width               = iconSize == null ? 32 : iconSize.Value;
                    temp.Height              = iconSize == null ? 32 : iconSize.Value;
                    temp.Margin              = iconMargin == null ? new Thickness(margin, 0, 0, 0) : iconMargin.Value;
                    temp.VerticalAlignment   = VerticalAlignment.Top;
                    temp.HorizontalAlignment = HorizontalAlignment.Left;
                    temp.Source              = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bit.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
                    temp.Name = "CurrentSpellIcon";

                    // Code smells here on hacky positioning and updating the icon
                    temp.Margin = new Thickness(103, 38, 0, 0);
                    main.CurrentIconGrid.Children.Clear();
                    main.CurrentIconGrid.Children.Add(temp);
                }
            }

            // Load all icons available if have not already
            if (!loadedAllIcons)
            {
                loadedAllIcons = true;

                List <Icon_DBC_Lookup> lookups = Lookups.ToList();
                foreach (var entry in lookups)
                {
                    var path = entry.Name;
                    if (!File.Exists(path + ".blp"))
                    {
                        Console.WriteLine("Warning: Icon not found: " + path + ".blp");
                        continue;
                    }
                    bool   loaded = false;
                    Bitmap bit    = null;
                    try
                    {
                        using (FileStream fileStream = new FileStream(path + ".blp", FileMode.Open))
                        {
                            using (BlpFile image = new BlpFile(fileStream))
                            {
                                bit    = image.getBitmap(0);
                                loaded = true;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Error loading image, unsupported BLP format: {path}.blp\n{e.Message}\n{e}");
                    }
                    if (!loaded)
                    {
                        continue;
                    }

                    System.Windows.Controls.Image temp = new System.Windows.Controls.Image();

                    temp.Width               = iconSize == null ? 32 : iconSize.Value;
                    temp.Height              = iconSize == null ? 32 : iconSize.Value;
                    temp.Margin              = iconMargin == null ? new Thickness(margin, 0, 0, 0) : iconMargin.Value;
                    temp.VerticalAlignment   = VerticalAlignment.Top;
                    temp.HorizontalAlignment = HorizontalAlignment.Left;
                    temp.Source              = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bit.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
                    temp.Name       = "Index_" + entry.Offset;
                    temp.ToolTip    = path;
                    temp.MouseDown += ImageDown;

                    main.IconGrid.Children.Add(temp);
                }
            }
        }