Exemplo n.º 1
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();
                }
            }
        }
Exemplo n.º 2
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");
            }
        }