public static void ExportDeck()
 {
     if (DeckList.Instance.ActiveDeck != null && Core.Game.IsInMenu)
     {
         DeckExporter.Export(DeckList.Instance.ActiveDeckVersion).Forget();
     }
 }
        private async void ExportDeck(Deck deck)
        {
            var export = true;

            if (Config.Instance.ShowExportingDialog)
            {
                var message  = $"1) Create a new (or open an existing) {deck.Class} deck.\n\n2) Leave the deck creation screen open.\n\n3) Click 'Export' and do not move your mouse or type until done.";
                var settings = new MessageDialogs.Settings {
                    AffirmativeButtonText = "Export"
                };
                var result = await this.ShowMessageAsync("Export " + deck.Name + " to Hearthstone", message, MessageDialogStyle.AffirmativeAndNegative, settings);

                export = result == MessageDialogResult.Affirmative;
            }
            if (export)
            {
                var controller = await this.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type.");

                Topmost = false;
                await Task.Delay(500);

                var success = await DeckExporter.Export(deck);

                await controller.CloseAsync();

                if (success)
                {
                    var hsDeck = HearthMirror.Reflection.GetEditedDeck();
                    if (hsDeck != null)
                    {
                        var existingHsId = DeckList.Instance.Decks.Where(x => x.DeckId != deck.DeckId).FirstOrDefault(x => x.HsId == hsDeck.Id);
                        if (existingHsId != null)
                        {
                            existingHsId.HsId = 0;
                        }
                        deck.HsId = hsDeck.Id;
                        DeckList.Save();
                    }
                }

                if (deck.MissingCards.Any())
                {
                    this.ShowMissingCardsMessage(deck);
                }
            }
        }
Пример #3
0
        private async void ExportDeck(Deck deck)
        {
            var export = true;

            if (Config.Instance.ShowExportingDialog)
            {
                var message =
                    string.Format(
                        "1) create a new {0} deck{1}.\n\n2) leave the deck creation screen open.\n\n3) do not move your mouse or type after clicking \"export\".",
                        deck.Class, (Config.Instance.AutoClearDeck ? " (or open an existing one to be cleared automatically)" : ""));

                if (deck.GetSelectedDeckVersion().Cards.Any(c => c.Name == "Stalagg" || c.Name == "Feugen"))
                {
                    message +=
                        "\n\nIMPORTANT: If you own golden versions of Feugen or Stalagg please make sure to configure\nOptions > Other > Exporting";
                }

                var settings = new MessageDialogs.Settings {
                    AffirmativeButtonText = "Export"
                };
                var result =
                    await
                    this.ShowMessageAsync("Export " + deck.Name + " to Hearthstone", message, MessageDialogStyle.AffirmativeAndNegative, settings);

                export = result == MessageDialogResult.Affirmative;
            }
            if (export)
            {
                var controller = await this.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type.");

                Topmost = false;
                await Task.Delay(500);

                await DeckExporter.Export(deck);

                await controller.CloseAsync();

                if (deck.MissingCards.Any())
                {
                    this.ShowMissingCardsMessage(deck);
                }
            }
        }
Пример #4
0
        private async void ExportDeck(Deck deck)
        {
            if (Config.Instance.ShowExportingDialog)
            {
                var message = $"1) Create a new (or open an existing) {deck.Class} deck.\n\n2) Leave the deck creation screen open.\n\n3) Click 'Export' and do not move your mouse or type until done.";
                var result  = await this.ShowMessageAsync("Export " + deck.Name + " to Hearthstone", message, AffirmativeAndNegative, new MessageDialogs.Settings {
                    AffirmativeButtonText = "Export"
                });

                if (result == MessageDialogResult.Negative)
                {
                    return;
                }
            }
            HearthMirror.Objects.Deck openDeck;
            var settings = new MessageDialogs.Settings()
            {
                AffirmativeButtonText = "Continue", NegativeButtonText = "Cancel"
            };

            while ((openDeck = Reflection.GetEditedDeck()) == null)
            {
                var result = await this.ShowMessageAsync("No open deck found", "Please open a deck for editing in Hearthstone before continuing.", AffirmativeAndNegative, settings);

                if (result == MessageDialogResult.Negative)
                {
                    return;
                }
            }
            var missingCards = ExportingHelper.GetMissingCards(deck).ToList();

            deck.MissingCards = missingCards;
            if (missingCards.Count > 0)
            {
                var result = await this.ShowMissingCardsMessage(deck, true);

                if (result == MessageDialogResult.Negative)
                {
                    return;
                }
            }
            string selectedClass;

            while ((selectedClass = Database.GetCardFromId(openDeck.Hero).PlayerClass) != deck.Class)
            {
                var result = await this.ShowMessageAsync("Incorrect class", $"Open deck is a {selectedClass} deck, but we are trying to import a {deck.Class} deck. Please create a deck with the correct class before continuing.", AffirmativeAndNegative, settings);

                if (result == MessageDialogResult.Negative)
                {
                    return;
                }
                openDeck = Reflection.GetEditedDeck();
            }
            while (!deck.StandardViable && !openDeck.IsWild)
            {
                var result = await this.ShowMessageAsync("Not a wild deck", "Open deck is a standard deck, but we are importing a wild deck. Please switch the deck to wild before continuing.", AffirmativeAndNegative, settings);

                if (result == MessageDialogResult.Negative)
                {
                    return;
                }
                openDeck = Reflection.GetEditedDeck();
            }
            var controller = await this.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type.");

            Topmost = false;
            await Task.Delay(500);

            var success = await DeckExporter.Export(deck, async() =>
            {
                if (controller != null)
                {
                    await controller.CloseAsync();
                }
                ActivateWindow();
                var result = await this.ShowMessageAsync("Importing interrupted", "Continue?", AffirmativeAndNegative,
                                                         new MessageDialogs.Settings()
                {
                    AffirmativeButtonText = "Continue", NegativeButtonText = "Cancel"
                });
                if (result == MessageDialogResult.Affirmative)
                {
                    controller = await this.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type.");
                }
                return(result == MessageDialogResult.Affirmative);
            });

            if (controller.IsOpen)
            {
                await controller.CloseAsync();
            }
            if (success)
            {
                var hsDeck = Reflection.GetEditedDeck();
                if (hsDeck != null)
                {
                    var existingHsId = DeckList.Instance.Decks.Where(x => x.DeckId != deck.DeckId).FirstOrDefault(x => x.HsId == hsDeck.Id);
                    if (existingHsId != null)
                    {
                        existingHsId.HsId = 0;
                    }
                    deck.HsId = hsDeck.Id;
                    DeckList.Save();
                }
            }
        }
        public async Task GetCardCounts(Deck deck)
        {
            var hsHandle = User32.GetHearthstoneWindow();

            if (!User32.IsHearthstoneInForeground())
            {
                //restore window and bring to foreground
                User32.ShowWindow(hsHandle, User32.SwRestore);
                User32.SetForegroundWindow(hsHandle);
                //wait it to actually be in foreground, else the rect might be wrong
                await Task.Delay(500);
            }
            if (!User32.IsHearthstoneInForeground())
            {
                MessageBox.Show("Can't find Hearthstone window.");
                Logger.WriteLine("Can't find Hearthstone window.", "ArenaImport");
                return;
            }
            await Task.Delay(1000);

            Core.Overlay.ForceHidden = true;
            Core.Overlay.UpdatePosition();
            const double xScale          = 0.013;
            const double yScale          = 0.017;
            const int    targetHue       = 53;
            const int    hueMargin       = 3;
            const int    numVisibleCards = 21;
            var          hsRect          = User32.GetHearthstoneRect(false);
            var          ratio           = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height);
            var          posX            = (int)DeckExporter.GetXPos(0.92, hsRect.Width, ratio);
            var          startY          = 71.0 / 768.0 * hsRect.Height;
            var          strideY         = 29.0 / 768.0 * hsRect.Height;
            int          width           = (int)Math.Round(hsRect.Width * xScale);
            int          height          = (int)Math.Round(hsRect.Height * yScale);

            for (var i = 0; i < Math.Min(numVisibleCards, deck.Cards.Count); i++)
            {
                var posY    = (int)(startY + strideY * i);
                var capture = Helper.CaptureHearthstone(new System.Drawing.Point(posX, posY), width, height, hsHandle);
                if (capture != null)
                {
                    var yellowPixels = 0;
                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            var pixel = capture.GetPixel(x, y);
                            if (Math.Abs(pixel.GetHue() - targetHue) < hueMargin)
                            {
                                yellowPixels++;
                            }
                        }
                    }
                    //Console.WriteLine(yellowPixels + " of " + width * height + " - " + yellowPixels / (double)(width * height));
                    //capture.Save("arenadeckimages/" + i + ".png");
                    var yellowPixelRatio = yellowPixels / (double)(width * height);
                    if (yellowPixelRatio > 0.25 && yellowPixelRatio < 50)
                    {
                        deck.Cards[i].Count = 2;
                    }
                }
            }

            if (deck.Cards.Count > numVisibleCards)
            {
                const int scrollClicksPerCard = 4;
                const int scrollDistance      = 120;
                var       clientPoint         = new System.Drawing.Point(posX, (int)startY);
                var       previousPos         = System.Windows.Forms.Cursor.Position;
                User32.ClientToScreen(hsHandle, ref clientPoint);
                System.Windows.Forms.Cursor.Position = new System.Drawing.Point(clientPoint.X, clientPoint.Y);
                for (int j = 0; j < scrollClicksPerCard * (deck.Cards.Count - numVisibleCards); j++)
                {
                    User32.mouse_event((uint)User32.MouseEventFlags.Wheel, 0, 0, -scrollDistance, UIntPtr.Zero);
                    await Task.Delay(30);
                }
                System.Windows.Forms.Cursor.Position = previousPos;
                await Task.Delay(100);

                var remainingCards = deck.Cards.Count - numVisibleCards;
                startY = 76.0 / 768.0 * hsRect.Height + (numVisibleCards - remainingCards) * strideY;
                for (int i = 0; i < remainingCards; i++)
                {
                    var posY    = (int)(startY + strideY * i);
                    var capture = Helper.CaptureHearthstone(new System.Drawing.Point(posX, posY), width, height, hsHandle);
                    if (capture != null)
                    {
                        var yellowPixels = 0;
                        for (int x = 0; x < width; x++)
                        {
                            for (int y = 0; y < height; y++)
                            {
                                var pixel = capture.GetPixel(x, y);
                                if (Math.Abs(pixel.GetHue() - targetHue) < hueMargin)
                                {
                                    yellowPixels++;
                                }
                            }
                        }
                        //Console.WriteLine(yellowPixels + " of " + width * height + " - " + yellowPixels / (double)(width * height));
                        //capture.Save("arenadeckimages/" + i + 21 + ".png");
                        var yellowPixelRatio = yellowPixels / (double)(width * height);
                        if (yellowPixelRatio > 0.25 && yellowPixelRatio < 50)
                        {
                            deck.Cards[numVisibleCards + i].Count = 2;
                        }
                    }
                }

                System.Windows.Forms.Cursor.Position = new System.Drawing.Point(clientPoint.X, clientPoint.Y);
                for (int j = 0; j < scrollClicksPerCard * (deck.Cards.Count - 21); j++)
                {
                    User32.mouse_event((uint)User32.MouseEventFlags.Wheel, 0, 0, scrollDistance, UIntPtr.Zero);
                    await Task.Delay(30);
                }
                System.Windows.Forms.Cursor.Position = previousPos;
            }

            Core.Overlay.ForceHidden = false;
            Core.Overlay.UpdatePosition();

            ActivateWindow();
        }
Пример #6
0
        public static async void ExportDeck(Deck deck, bool autoFinish = false)
        {
            var export = true;
            var info   = new ExportingInfo();
            int pause  = 1000;

            if (Config.Instance.ShowExportingDialog)
            {
                var message =
                    $"1) create a new {deck.Class} deck{(Config.Instance.AutoClearDeck ? " (or open an existing one to be cleared automatically)" : "")}.\n\n2) leave the deck creation screen open.\n\n3) do not move your mouse or type after clicking \"export\".";

                if (deck.GetSelectedDeckVersion().Cards.Any(c => c.Name == "Stalagg" || c.Name == "Feugen"))
                {
                    message +=
                        "\n\nIMPORTANT: If you own golden versions of Feugen or Stalagg please make sure to configure\nOptions > Other > Exporting";
                }

                var settings = new Hearthstone_Deck_Tracker.Windows.MessageDialogs.Settings {
                    AffirmativeButtonText = "Export"
                };
                var result =
                    await
                    Hearthstone_Deck_Tracker.API.Core.MainWindow.ShowMessageAsync("Export " + deck.Name + " to Hearthstone", message, MessageDialogStyle.AffirmativeAndNegative, settings);

                export = result == MessageDialogResult.Affirmative;
            }
            if (export)
            {
                Hearthstone_Deck_Tracker.API.Core.MainWindow.Topmost = false;

                var inForeground = await ExportingHelper.EnsureHearthstoneInForeground(info.HsHandle);

                if (!inForeground)
                {
                    return;
                }

                var controller = await Hearthstone_Deck_Tracker.API.Core.MainWindow.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type.");

                await Task.Delay(pause);
                await ClickOnPoint(info, deck.Class);

                await Task.Delay(pause);
                await ClickOnPoint(info, "ClassChoose");

                await Task.Delay(pause);
                await ClickOnPoint(info, "RecipeCustom");

                await Task.Delay(pause);
                await ClickOnPoint(info, "RecipeChoose");

                await Task.Delay(pause);

                await DeckExporter.Export(deck);

                await controller.CloseAsync();

                if (deck.MissingCards.Any())
                {
                    Hearthstone_Deck_Tracker.Windows.MessageDialogs.ShowMissingCardsMessage(Hearthstone_Deck_Tracker.API.Core.MainWindow, deck);
                }
            }

            if (autoFinish)
            {
                await ClickOnPoint(info, "Done");

                await Task.Delay(pause);
                await ClickOnPoint(info, "QuestionYes");
            }
        }