internal async void BtnDeleteDeck_Click(object sender, RoutedEventArgs e)
		{
			var decks = DeckPickerList.SelectedDecks;
			if(!decks.Any())
				return;

			var settings = new MessageDialogs.Settings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"};
			var keepStatsInfo = Config.Instance.KeepStatsWhenDeletingDeck
				                    ? "The stats will be kept (can be changed in options)"
				                    : "The stats will be deleted (can be changed in options)";
			var result =
				await
				this.ShowMessageAsync("Deleting " + (decks.Count == 1 ? decks.First().Name : decks.Count + " decks"),
				                      "Are you Sure?\n" + keepStatsInfo, MessageDialogStyle.AffirmativeAndNegative, settings);
			if(result == MessageDialogResult.Negative)
				return;
			DeckManagerEvents.OnDeckDeleted.Execute(decks);
			SelectDeck(null, true);
			foreach(var deck in decks)
				DeleteDeck(deck, false);
			DeckStatsList.Save();
			DeckList.Save();
			DeckPickerList.UpdateDecks();
			DeckPickerList.UpdateArchivedClassVisibility();
		}
		private async void ExportDeck(Deck deck)
		{
			var export = true;
			if(Config.Instance.ShowExportingDialog)
			{
				var message =
					string.Format(
					              "1) create a new, empty {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);
			}
		}
Ejemplo n.º 3
0
        internal async void BtnDeleteDeck_Click(object sender, RoutedEventArgs e)
        {
            var decks = DeckPickerList.SelectedDecks;

            if (!decks.Any())
            {
                return;
            }

            var settings = new MessageDialogs.Settings {
                AffirmativeButtonText = "Yes", NegativeButtonText = "No"
            };
            var keepStatsInfo = Config.Instance.KeepStatsWhenDeletingDeck
                                                    ? "The stats will be kept (can be changed in options)"
                                                    : "The stats will be deleted (can be changed in options)";
            var result =
                await
                this.ShowMessageAsync("Deleting " + (decks.Count == 1 ? decks.First().Name : decks.Count + " decks"),
                                      "Are you Sure?\n" + keepStatsInfo, MessageDialogStyle.AffirmativeAndNegative, settings);

            if (result == MessageDialogResult.Negative)
            {
                return;
            }
            DeckManagerEvents.OnDeckDeleted.Execute(decks);
            SelectDeck(null, true);
            foreach (var deck in decks)
            {
                DeleteDeck(deck, false);
            }
            DeckStatsList.Save();
            DeckList.Save();
            DeckPickerList.UpdateDecks();
            DeckPickerList.UpdateArchivedClassVisibility();
        }
Ejemplo n.º 4
0
        internal async void BtnName_Click(object sender, RoutedEventArgs e)
        {
            var deck = DeckPickerList.SelectedDecks.FirstOrDefault();

            if (deck == null)
            {
                return;
            }
            var settings = new MessageDialogs.Settings {
                AffirmativeButtonText = "set", NegativeButtonText = "cancel", DefaultText = deck.Name
            };
            var newName = await this.ShowInputAsync("Set deck name", "", settings);

            if (!string.IsNullOrEmpty(newName) && deck.Name != newName)
            {
                deck.Name = newName;
                deck.Edited();
                if (deck.DeckStats.Games.Any())
                {
                    foreach (var game in deck.DeckStats.Games)
                    {
                        game.DeckName = newName;
                    }
                    DeckStatsList.Save();
                }

                DeckList.Save();
                DeckPickerList.UpdateDecks();
                if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn)
                {
                    HearthStatsManager.UpdateDeckAsync(deck, true, true);
                }
            }
        }
		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);
			}
		}
        internal async void ImportFromIdString()
        {
            try
            {
                var settings  = new MessageDialogs.Settings();
                var clipboard = Clipboard.ContainsText() ? Clipboard.GetText() : "";
                if (clipboard.Count(c => c == ':') > 0 && clipboard.Count(c => c == ';') > 0)
                {
                    settings.DefaultText = clipboard;
                }

                //import dialog
                var idString =
                    await
                    this.ShowInputAsync("Import deck",
                                        "id:count;id2:count2;... (e.g. EX1_050:2;EX1_556:1;)\nObtained from: \nEXPORT > COPY IDS TO CLIPBOARD",
                                        settings);

                if (string.IsNullOrEmpty(idString))
                {
                    return;
                }
                var deck = new Deck();
                foreach (var entry in idString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var splitEntry = entry.Split(':');
                    if (splitEntry.Length != 2)
                    {
                        continue;
                    }
                    var card = Database.GetCardFromId(splitEntry[0]);
                    if (card.Id == "UNKNOWN")
                    {
                        continue;
                    }
                    int count;
                    int.TryParse(splitEntry[1], out count);
                    card.Count = count;

                    if (string.IsNullOrEmpty(deck.Class) && card.GetPlayerClass != "Neutral")
                    {
                        deck.Class = card.GetPlayerClass;
                    }

                    deck.Cards.Add(card);
                }
                if (Config.Instance.AutoSaveOnImport)
                {
                    DeckManager.SaveDeck(deck);
                }
                else
                {
                    ShowDeckEditorFlyout(deck, true);
                }
            }
            catch (Exception ex)
            {
                Log.Info("Error importing deck from clipboard(id string): " + ex);
            }
        }
        internal async void ShowEditDeckNameDialog(Deck deck)
        {
            if (deck == null)
            {
                return;
            }
            var settings = new MessageDialogs.Settings {
                AffirmativeButtonText = "set", NegativeButtonText = "cancel", DefaultText = deck.Name
            };
            var newName = await this.ShowInputAsync("Set deck name", "", settings);

            if (string.IsNullOrEmpty(newName) || deck.Name == newName)
            {
                return;
            }
            deck.Name = newName;
            deck.Edited();
            if (deck.DeckStats.Games.Any())
            {
                foreach (var game in deck.DeckStats.Games)
                {
                    game.DeckName = newName;
                }
                DeckStatsList.Save();
            }

            DeckList.Save();
            DeckPickerList.UpdateDecks();
        }
Ejemplo n.º 8
0
        internal async void BtnName_Click(object sender, RoutedEventArgs e)
        {
            var deck = DeckPickerList.SelectedDecks.FirstOrDefault();

            if (deck == null)
            {
                return;
            }
            var settings = new MessageDialogs.Settings {
                AffirmativeButtonText = "set", NegativeButtonText = "cancel", DefaultText = deck.Name
            };
            var newName = await this.ShowInputAsync("Set deck name", "", settings);

            if (string.IsNullOrEmpty(newName) || deck.Name == newName)
            {
                return;
            }
            deck.Name = newName;
            deck.Edited();
            if (deck.DeckStats.Games.Any())
            {
                foreach (var game in deck.DeckStats.Games)
                {
                    game.DeckName = newName;
                }
                DeckStatsList.Save();
            }

            DeckList.Save();
            DeckPickerList.UpdateDecks();
        }
Ejemplo n.º 9
0
		private static async void ShowNewUpdateMessage(Version newVersion, bool beta)
		{
			if(_showingUpdateMessage)
				return;
			_showingUpdateMessage = true;

			const string releaseDownloadUrl = @"https://github.com/Epix37/Hearthstone-Deck-Tracker/releases";
			var settings = new MessageDialogs.Settings {AffirmativeButtonText = "Download", NegativeButtonText = "Not now"};
			if(newVersion == null)
			{
				_showingUpdateMessage = false;
				return;
			}
			try
			{
				await Task.Delay(10000);
				Core.MainWindow.ActivateWindow();
				while(Core.MainWindow.Visibility != Visibility.Visible || Core.MainWindow.WindowState == WindowState.Minimized)
					await Task.Delay(100);
				var newVersionString = $"{newVersion.Major}.{newVersion.Minor}.{newVersion.Build}";
				var betaString = beta ? " BETA" : "";
				var result =
					await
					Core.MainWindow.ShowMessageAsync("New" + betaString + " Update available!", "Press \"Download\" to automatically download.",
					                                 MessageDialogStyle.AffirmativeAndNegative, settings);

				if(result == MessageDialogResult.Affirmative)
				{
					//recheck, in case there was no immediate response to the dialog
					if((DateTime.Now - _lastUpdateCheck) > new TimeSpan(0, 10, 0))
					{
						newVersion = await Helper.CheckForUpdates(beta);
						if(newVersion != null)
							newVersionString = $"{newVersion.Major}.{newVersion.Minor}.{newVersion.Build}";
					}
					try
					{
						Process.Start("HDTUpdate.exe", $"{Process.GetCurrentProcess().Id} {newVersionString}");
						Core.MainWindow.Close();
						Application.Current.Shutdown();
					}
					catch
					{
						Logger.WriteLine("Error starting updater");
						Process.Start(releaseDownloadUrl);
					}
				}
				else
					TempUpdateCheckDisabled = true;

				_showingUpdateMessage = false;
			}
			catch(Exception e)
			{
				_showingUpdateMessage = false;
				Logger.WriteLine("Error showing new update message\n" + e.Message);
			}
		}
		private async Task<string> InputDeckURL()
		{
			var settings = new MessageDialogs.Settings();
			var validUrls = DeckImporter.Websites.Keys.Select(x => x.Split('.')[0]).ToArray();
			try
			{
				var clipboard = Clipboard.ContainsText() ? new string(Clipboard.GetText().Take(1000).ToArray()) : "";
				if(validUrls.Any(clipboard.Contains))
					settings.DefaultText = clipboard;
			}
			catch(Exception e)
			{
				Log.Error(e);
				return null;
			}

			if(Config.Instance.DisplayNetDeckAd)
			{
				var result =
					await
					this.ShowMessageAsync("NetDeck",
					                      "For easier (one-click!) web importing check out the NetDeck Chrome Extension!\n\n(This message will not be displayed again, no worries.)",
					                      MessageDialogStyle.AffirmativeAndNegative,
					                      new MessageDialogs.Settings {AffirmativeButtonText = "Show me!", NegativeButtonText = "No thanks"});

				if(result == MessageDialogResult.Affirmative)
				{
					Helper.TryOpenUrl("https://chrome.google.com/webstore/detail/netdeck/lpdbiakcpmcppnpchohihcbdnojlgeel");
					var enableOptionResult =
						await
						this.ShowMessageAsync("Enable one-click importing?",
						                      "Would you like to enable one-click importing via NetDeck?\n(options > other > importing)",
						                      MessageDialogStyle.AffirmativeAndNegative,
						                      new MessageDialogs.Settings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"});
					if(enableOptionResult == MessageDialogResult.Affirmative)
					{
						Options.OptionsTrackerImporting.CheckboxImportNetDeck.IsChecked = true;
						Config.Instance.NetDeckClipboardCheck = true;
						Config.Save();
					}
				}

				Config.Instance.DisplayNetDeckAd = false;
				Config.Save();
			}


			//import dialog
			var url =
				await this.ShowInputAsync("Import deck", "Supported websites:\n" + validUrls.Aggregate((x, next) => x + ", " + next), settings);
			return url;
		}
        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);
                }
            }
        }
		private async Task<string> InputDeckURL()
		{
			var settings = new MessageDialogs.Settings();
			var validUrls = DeckImporter.Websites.Keys.Select(x => x.Split('.')[0]).ToArray();
			try
			{
				var clipboard = Clipboard.ContainsText() ? new string(Clipboard.GetText().Take(1000).ToArray()) : "";
				if(validUrls.Any(clipboard.Contains))
					settings.DefaultText = clipboard;
			}
			catch(Exception e)
			{
				Log.Error(e);
				return null;
			}

			return await this.ShowInputAsync("Import deck", "Supported websites:\n" + validUrls.Aggregate((x, next) => x + ", " + next), settings);
		}
Ejemplo n.º 13
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);
                }
            }
        }
Ejemplo n.º 14
0
        private async Task <string> InputDeckURL()
        {
            var settings  = new MessageDialogs.Settings();
            var validUrls = DeckImporter.Websites.Keys.Select(x => x.Split('.')[0]).ToArray();

            try
            {
                var clipboard = Clipboard.ContainsText() ? new string(Clipboard.GetText().Take(1000).ToArray()) : "";
                if (validUrls.Any(clipboard.Contains))
                {
                    settings.DefaultText = clipboard;
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }

            return(await this.ShowInputAsync("Import deck", "Supported websites:\n" + validUrls.Aggregate((x, next) => x + ", " + next), settings));
        }
Ejemplo n.º 15
0
		private static async void ShowNewUpdateMessage(bool beta)
		{
			if(_showingUpdateMessage)
				return;
			_showingUpdateMessage = true;
			
			var settings = new MessageDialogs.Settings {AffirmativeButtonText = "Download", NegativeButtonText = "Not now"};
			if(_newVersion == null)
			{
				_showingUpdateMessage = false;
				return;
			}
			try
			{
				await Task.Delay(10000);
				Core.MainWindow.ActivateWindow();
				while(Core.MainWindow.Visibility != Visibility.Visible || Core.MainWindow.WindowState == WindowState.Minimized)
					await Task.Delay(100);
				var betaString = beta ? " BETA" : "";
				var result =
					await
					Core.MainWindow.ShowMessageAsync("New" + betaString + " Update available!", "Press \"Download\" to automatically download.",
					                                 MessageDialogStyle.AffirmativeAndNegative, settings);

				if(result == MessageDialogResult.Affirmative)
					StartUpdate();
				else
				{
					TempUpdateCheckDisabled = true;
					StatusBar.Visibility = Visibility.Visible;
				}

				_showingUpdateMessage = false;
			}
			catch(Exception e)
			{
				_showingUpdateMessage = false;
				Log.Error("Error showing new update message\n" + e);
			}
		}
Ejemplo n.º 16
0
        internal async void ShowDeleteDecksMessage(IEnumerable <Deck> decks)
        {
            if (decks == null)
            {
                return;
            }
            var decksList = decks.ToList();

            if (!decksList.Any())
            {
                return;
            }

            var settings = new MessageDialogs.Settings {
                AffirmativeButtonText = LocUtil.Get(nameof(Strings.Enum_YesNo_Yes)), NegativeButtonText = LocUtil.Get(nameof(Strings.Enum_YesNo_No))
            };
            var keepStatsInfo = Config.Instance.KeepStatsWhenDeletingDeck
                                                    ? "The stats will be kept (can be changed in options)"
                                                    : "The stats will be deleted (can be changed in options)";
            var result =
                await
                this.ShowMessageAsync("Deleting " + (decksList.Count == 1 ? decksList.First().Name : decksList.Count + " decks"),
                                      "Are you Sure?\n" + keepStatsInfo, MessageDialogStyle.AffirmativeAndNegative, settings);

            if (result == MessageDialogResult.Negative)
            {
                return;
            }
            foreach (var deck in decksList)
            {
                DeleteDeck(deck, false);
            }
            DeckStatsList.Save();
            DeckList.Save();
            DeckPickerList.UpdateDecks();
            DeckPickerList.UpdateArchivedClassVisibility();
            DeckManagerEvents.OnDeckDeleted.Execute(decksList);
        }
		private async void EditNote(GameStats selected)
		{
			if(selected == null)
				return;
			var settings = new MessageDialogs.Settings {DefaultText = selected.Note};
			string newNote;
			if(Config.Instance.StatsInWindow)
				newNote = await Core.Windows.StatsWindow.ShowInputAsync("Note", "", settings);
			else
				newNote = await Core.MainWindow.ShowInputAsync("Note", "", settings);
			if(newNote == null)
				return;
			selected.Note = newNote;
			DeckStatsList.Save();
			Refresh();
		}
Ejemplo n.º 18
0
        public async void SaveDeck(bool overwrite, SerializableVersion newVersion, bool workInProgressDeck = false)
        {
            var deckName = TextBoxDeckName.Text;

            if (string.IsNullOrEmpty(deckName))
            {
                var settings = new MessageDialogs.Settings {
                    AffirmativeButtonText = "Set", DefaultText = deckName
                };

                var name = await this.ShowInputAsync("No name set", "Please set a name for the deck", settings);

                if (string.IsNullOrEmpty(name))
                {
                    return;
                }

                deckName             = name;
                TextBoxDeckName.Text = name;
            }

            if (_newDeck.Cards.Sum(c => c.Count) != 30 && workInProgressDeck == false)
            {
                var settings = new MessageDialogs.Settings {
                    AffirmativeButtonText = "Yes", NegativeButtonText = "No"
                };

                var result =
                    await
                    this.ShowMessageAsync("Not 30 cards",
                                          $"Deck contains {_newDeck.Cards.Sum(c => c.Count)} cards. Is this what you want to save anyway?", MessageDialogStyle.AffirmativeAndNegative, settings);

                if (result != MessageDialogResult.Affirmative)
                {
                    return;
                }
            }

            var previousVersion = _newDeck.Version;

            if (overwrite && (_newDeck.Version != newVersion))
            {
                AddDeckHistory();
                _newDeck.Version                  = newVersion;
                _newDeck.SelectedVersion          = newVersion;
                _newDeck.HearthStatsDeckVersionId = "";
            }

            if (EditingDeck && overwrite)
            {
                DeckList.Instance.Decks.Remove(_newDeck);
            }

            var oldDeckName = _newDeck.Name;

            _newDeck.Name = deckName;

            var newDeckClone = (Deck)_newDeck.Clone();

            newDeckClone.Archived = false;

            DeckList.Instance.Decks.Add(newDeckClone);

            newDeckClone.LastEdited = DateTime.Now;

            DeckList.Save();

            Log.Info("Saved Decks");

            if (EditingDeck)
            {
                TagControlEdit.SetSelectedTags(new List <string>());
                if (deckName != oldDeckName)
                {
                    var statsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(_newDeck));
                    if (statsEntry != null)
                    {
                        if (overwrite)
                        {
                            statsEntry.Name = deckName;
                            Log.Info("Deck has new name, updated deckstats");
                            foreach (var game in statsEntry.Games)
                            {
                                game.DeckName = deckName;
                            }
                        }
                        else
                        {
                            var newStatsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(_newDeck));
                            if (newStatsEntry == null)
                            {
                                newStatsEntry = new DeckStats(_newDeck);
                                DeckStatsList.Instance.DeckStats.Add(newStatsEntry);
                            }
                            foreach (var game in statsEntry.Games)
                            {
                                newStatsEntry.AddGameResult(game.CloneWithNewId());
                            }
                            Log.Info("cloned gamestats for \"Set as new\"");
                        }
                        DeckStatsList.Save();
                    }
                }
            }


            if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn)
            {
                Log.Info("auto uploading new/edited deck");
                if (EditingDeck)
                {
                    if (previousVersion != newVersion)
                    {
                        HearthStatsManager.UploadVersionAsync(newDeckClone, _originalDeck.HearthStatsIdForUploading, background: true).Forget();
                    }
                    else
                    {
                        HearthStatsManager.UpdateDeckAsync(newDeckClone, background: true).Forget();
                    }
                }
                else
                {
                    HearthStatsManager.UploadDeckAsync(newDeckClone, background: true).Forget();
                }
            }

            if (EditingDeck)
            {
                DeckManagerEvents.OnDeckUpdated.Execute(newDeckClone);
            }
            else
            {
                DeckManagerEvents.OnDeckCreated.Execute(newDeckClone);
            }


            EditingDeck = false;

            foreach (var tag in _newDeck.Tags)
            {
                SortFilterDecksFlyout.AddSelectedTag(tag);
            }

            DeckPickerList.SelectDeckAndAppropriateView(newDeckClone);
            DeckPickerList.UpdateDecks(forceUpdate: new[] { newDeckClone });
            SelectDeck(newDeckClone, true);
            CloseNewDeck();
            ClearNewDeckSection();
        }
		private async void ButtonEditNote_OnClick(object sender, RoutedEventArgs e)
		{
			if(SelectedGame == null)
				return;
			var settings = new MessageDialogs.Settings {DefaultText = SelectedGame.Note};
			string newNote;
			if(Config.Instance.StatsInWindow)
				newNote = await Core.Windows.StatsWindow.ShowInputAsync("Note", "", settings);
			else
				newNote = await Core.MainWindow.ShowInputAsync("Note", "", settings);
			if(newNote == null)
				return;
			SelectedGame.Note = newNote;
			DeckStatsList.Save();
			DefaultDeckStats.Save();
		}
		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;
			}
			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();
				}
			}
			if(deck.MissingCards.Any())
				this.ShowMissingCardsMessage(deck);
		}
		internal async void BtnName_Click(object sender, RoutedEventArgs e)
		{
			var deck = DeckPickerList.SelectedDecks.FirstOrDefault();
			if(deck == null)
				return;
			var settings = new MessageDialogs.Settings {AffirmativeButtonText = "set", NegativeButtonText = "cancel", DefaultText = deck.Name};
			var newName = await this.ShowInputAsync("Set deck name", "", settings);
			if(!string.IsNullOrEmpty(newName) && deck.Name != newName)
			{
				deck.Name = newName;
				deck.Edited();
				if(deck.DeckStats.Games.Any())
				{
					foreach(var game in deck.DeckStats.Games)
						game.DeckName = newName;
					DeckStatsList.Save();
				}

				DeckList.Save();
				DeckPickerList.UpdateDecks();
				if(Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn)
					HearthStatsManager.UpdateDeckAsync(deck, true, true);
			}
		}
		private async void BtnIdString_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				var settings = new MessageDialogs.Settings();
				var clipboard = Clipboard.ContainsText() ? Clipboard.GetText() : "";
				if(clipboard.Count(c => c == ':') > 0 && clipboard.Count(c => c == ';') > 0)
					settings.DefaultText = clipboard;

				//import dialog
				var idString =
					await
					this.ShowInputAsync("Import deck",
					                    "id:count;id2:count2;... (e.g. EX1_050:2;EX1_556:1;)\nObtained from: \nEXPORT > COPY IDS TO CLIPBOARD",
					                    settings);
				if(string.IsNullOrEmpty(idString))
					return;
				var deck = new Deck();
				foreach(var entry in idString.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries))
				{
					var splitEntry = entry.Split(':');
					if(splitEntry.Length != 2)
						continue;
					var card = Database.GetCardFromId(splitEntry[0]);
					if(card.Id == "UNKNOWN")
						continue;
					int count;
					int.TryParse(splitEntry[1], out count);
					card.Count = count;

					if(string.IsNullOrEmpty(deck.Class) && card.GetPlayerClass != "Neutral")
						deck.Class = card.GetPlayerClass;

					deck.Cards.Add(card);
				}
				SetNewDeck(deck);
				if(Config.Instance.AutoSaveOnImport)
					SaveDeckWithOverwriteCheck();
			}
			catch(Exception ex)
			{
				Logger.WriteLine("Error importing deck from clipboard(id string): " + ex, "Import");
			}
		}
Ejemplo n.º 23
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();
                }
            }
        }
		private async Task<string> InputDeckURL()
		{
			var settings = new MessageDialogs.Settings();
			var clipboard = Clipboard.ContainsText() ? Clipboard.GetText() : "";
			var validUrls = new[]
			{
				"hearthstats",
				"hss.io",
				"hearthpwn",
				"hearthhead",
				"hearthstoneplayers",
				"tempostorm",
				"hearthstonetopdeck",
				"hearthnews.fr",
				"arenavalue",
				"hearthstone-decks",
				"heartharena",
				"hearthstoneheroes",
				"elitedecks",
				"icy-veins",
				"hearthbuilder"
			};
			if(validUrls.Any(clipboard.Contains))
				settings.DefaultText = clipboard;

			if(Config.Instance.DisplayNetDeckAd)
			{
				var result =
					await
					this.ShowMessageAsync("NetDeck",
					                      "For easier (one-click!) web importing check out the NetDeck Chrome Extension!\n\n(This message will not be displayed again, no worries.)",
					                      MessageDialogStyle.AffirmativeAndNegative,
					                      new MessageDialogs.Settings {AffirmativeButtonText = "Show me!", NegativeButtonText = "No thanks"});

				if(result == MessageDialogResult.Affirmative)
				{
					Process.Start("https://chrome.google.com/webstore/detail/netdeck/lpdbiakcpmcppnpchohihcbdnojlgeel");
					var enableOptionResult =
						await
						this.ShowMessageAsync("Enable one-click importing?",
						                      "Would you like to enable one-click importing via NetDeck?\n(options > other > importing)",
						                      MessageDialogStyle.AffirmativeAndNegative,
						                      new MessageDialogs.Settings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"});
					if(enableOptionResult == MessageDialogResult.Affirmative)
					{
						Options.OptionsTrackerImporting.CheckboxImportNetDeck.IsChecked = true;
						Config.Instance.NetDeckClipboardCheck = true;
						Config.Save();
					}
				}

				Config.Instance.DisplayNetDeckAd = false;
				Config.Save();
			}


			//import dialog
			var url =
				await this.ShowInputAsync("Import deck", "Supported websites:\n" + validUrls.Aggregate((x, next) => x + ", " + next), settings);
			return url;
		}
        private async Task <string> InputDeckURL()
        {
            var settings  = new MessageDialogs.Settings();
            var validUrls = DeckImporter.Websites.Keys.Select(x => x.Split('.')[0]).ToArray();

            try
            {
                var clipboard = Clipboard.ContainsText() ? new string(Clipboard.GetText().Take(1000).ToArray()) : "";
                if (validUrls.Any(clipboard.Contains))
                {
                    settings.DefaultText = clipboard;
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }

            if (Config.Instance.DisplayNetDeckAd)
            {
                var result =
                    await
                    this.ShowMessageAsync("NetDeck",
                                          "For easier (one-click!) web importing check out the NetDeck Chrome Extension!\n\n(This message will not be displayed again, no worries.)",
                                          MessageDialogStyle.AffirmativeAndNegative,
                                          new MessageDialogs.Settings {
                    AffirmativeButtonText = "Show me!", NegativeButtonText = "No thanks"
                });

                if (result == MessageDialogResult.Affirmative)
                {
                    Helper.TryOpenUrl("https://chrome.google.com/webstore/detail/netdeck/lpdbiakcpmcppnpchohihcbdnojlgeel");
                    var enableOptionResult =
                        await
                        this.ShowMessageAsync("Enable one-click importing?",
                                              "Would you like to enable one-click importing via NetDeck?\n(options > other > importing)",
                                              MessageDialogStyle.AffirmativeAndNegative,
                                              new MessageDialogs.Settings {
                        AffirmativeButtonText = "Yes", NegativeButtonText = "No"
                    });

                    if (enableOptionResult == MessageDialogResult.Affirmative)
                    {
                        Options.OptionsTrackerImporting.CheckboxImportNetDeck.IsChecked = true;
                        Config.Instance.NetDeckClipboardCheck = true;
                        Config.Save();
                    }
                }

                Config.Instance.DisplayNetDeckAd = false;
                Config.Save();
            }


            //import dialog
            var url =
                await this.ShowInputAsync("Import deck", "Supported websites:\n" + validUrls.Aggregate((x, next) => x + ", " + next), settings);

            return(url);
        }
        private async Task <string> InputDeckURL()
        {
            var settings  = new MessageDialogs.Settings();
            var clipboard = Clipboard.ContainsText() ? Clipboard.GetText() : "";
            var validUrls = new[]
            {
                "hearthstats",
                "hss.io",
                "hearthpwn",
                "hearthhead",
                "hearthstoneplayers",
                "tempostorm",
                "hearthstonetopdeck",
                "hearthnews.fr",
                "arenavalue",
                "hearthstone-decks",
                "heartharena",
                "hearthstoneheroes",
                "elitedecks",
                "icy-veins",
                "hearthbuilder"
            };

            if (validUrls.Any(clipboard.Contains))
            {
                settings.DefaultText = clipboard;
            }

            if (Config.Instance.DisplayNetDeckAd)
            {
                var result =
                    await
                    this.ShowMessageAsync("NetDeck",
                                          "For easier (one-click!) web importing check out the NetDeck Chrome Extension!\n\n(This message will not be displayed again, no worries.)",
                                          MessageDialogStyle.AffirmativeAndNegative,
                                          new MessageDialogs.Settings {
                    AffirmativeButtonText = "Show me!", NegativeButtonText = "No thanks"
                });

                if (result == MessageDialogResult.Affirmative)
                {
                    Process.Start("https://chrome.google.com/webstore/detail/netdeck/lpdbiakcpmcppnpchohihcbdnojlgeel");
                    var enableOptionResult =
                        await
                        this.ShowMessageAsync("Enable one-click importing?",
                                              "Would you like to enable one-click importing via NetDeck?\n(options > other > importing)",
                                              MessageDialogStyle.AffirmativeAndNegative,
                                              new MessageDialogs.Settings {
                        AffirmativeButtonText = "Yes", NegativeButtonText = "No"
                    });

                    if (enableOptionResult == MessageDialogResult.Affirmative)
                    {
                        Options.OptionsTrackerImporting.CheckboxImportNetDeck.IsChecked = true;
                        Config.Instance.NetDeckClipboardCheck = true;
                        Config.Save();
                    }
                }

                Config.Instance.DisplayNetDeckAd = false;
                Config.Save();
            }


            //import dialog
            var url =
                await this.ShowInputAsync("Import deck", "Supported websites:\n" + validUrls.Aggregate((x, next) => x + ", " + next), settings);

            return(url);
        }
		public async void SaveDeck(bool overwrite, SerializableVersion newVersion, bool workInProgressDeck = false)
		{
			var deckName = TextBoxDeckName.Text;

			if(string.IsNullOrEmpty(deckName))
			{
				var settings = new MessageDialogs.Settings {AffirmativeButtonText = "Set", DefaultText = deckName};

				var name = await this.ShowInputAsync("No name set", "Please set a name for the deck", settings);

				if(string.IsNullOrEmpty(name))
					return;

				deckName = name;
				TextBoxDeckName.Text = name;
			}

			if(_newDeck.Cards.Sum(c => c.Count) != 30 && workInProgressDeck == false)
			{
				var settings = new MessageDialogs.Settings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"};

				var result =
					await
					this.ShowMessageAsync("Not 30 cards",
										  $"Deck contains {_newDeck.Cards.Sum(c => c.Count)} cards. Is this what you want to save anyway?", MessageDialogStyle.AffirmativeAndNegative, settings);
				if(result != MessageDialogResult.Affirmative)
					return;
			}

			var previousVersion = _newDeck.Version;
			if(overwrite && (_newDeck.Version != newVersion))
			{
				AddDeckHistory();
				_newDeck.Version = newVersion;
				_newDeck.SelectedVersion = newVersion;
				_newDeck.HearthStatsDeckVersionId = "";
			}

			if(EditingDeck && overwrite)
				DeckList.Instance.Decks.Remove(_newDeck);

			var oldDeckName = _newDeck.Name;

			_newDeck.Name = deckName;

			var newDeckClone = (Deck)_newDeck.Clone();
			newDeckClone.Archived = false;

			DeckList.Instance.Decks.Add(newDeckClone);

			newDeckClone.LastEdited = DateTime.Now;

			DeckList.Save();

			Log.Info("Saved Decks");

			if(EditingDeck)
			{
				TagControlEdit.SetSelectedTags(new List<string>());
				if(deckName != oldDeckName)
				{
					var statsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(_newDeck));
					if(statsEntry != null)
					{
						if(overwrite)
						{
							statsEntry.Name = deckName;
							Log.Info("Deck has new name, updated deckstats");
							foreach(var game in statsEntry.Games)
								game.DeckName = deckName;
						}
						else
						{
							var newStatsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(_newDeck));
							if(newStatsEntry == null)
							{
								newStatsEntry = new DeckStats(_newDeck);
								DeckStatsList.Instance.DeckStats.Add(newStatsEntry);
							}
							foreach(var game in statsEntry.Games)
								newStatsEntry.AddGameResult(game.CloneWithNewId());
							Log.Info("cloned gamestats for \"Set as new\"");
						}
						DeckStatsList.Save();
					}
				}
			}


			if(Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn)
			{
				Log.Info("auto uploading new/edited deck");
				if(EditingDeck)
				{
					if(previousVersion != newVersion)
						HearthStatsManager.UploadVersionAsync(newDeckClone, _originalDeck.HearthStatsIdForUploading, background: true).Forget();
					else
						HearthStatsManager.UpdateDeckAsync(newDeckClone, background: true).Forget();
				}
				else
					HearthStatsManager.UploadDeckAsync(newDeckClone, background: true).Forget();
			}

			if(EditingDeck)
				DeckManagerEvents.OnDeckUpdated.Execute(newDeckClone);
			else
				DeckManagerEvents.OnDeckCreated.Execute(newDeckClone);


			EditingDeck = false;

			foreach(var tag in _newDeck.Tags)
				SortFilterDecksFlyout.AddSelectedTag(tag);

			DeckPickerList.SelectDeckAndAppropriateView(newDeckClone);
			DeckPickerList.UpdateDecks(forceUpdate: new[] {newDeckClone});
			SelectDeck(newDeckClone, true);
			CloseNewDeck();
			ClearNewDeckSection();
		}