private void ButtonRemoveTag_Click(object sender, RoutedEventArgs e) { tbDataLoad.Text = resources.GetString("LOCHowLongToBeatProgressBarTag"); pbDataLoad.IsIndeterminate = true; DataLoad.Visibility = Visibility.Visible; spSettings.Visibility = Visibility.Hidden; tokenSource = new CancellationTokenSource(); ct = tokenSource.Token; var taskSystem = Task.Run(() => { ct.ThrowIfCancellationRequested(); foreach (Game game in PlayniteApi.Database.Games) { HowLongToBeatData.RemoveAllTag(PlayniteApi, game); if (ct.IsCancellationRequested) { ct.ThrowIfCancellationRequested(); } } }, tokenSource.Token) .ContinueWith(antecedent => { Application.Current.Dispatcher.Invoke(new Action(() => { DataLoad.Visibility = Visibility.Collapsed; spSettings.Visibility = Visibility.Visible; })); }); }
public void SetHltbData(long Playtime, HowLongToBeatData gameData, HowLongToBeatSettings settings) { _gameData = gameData; _Playtime = Playtime; _settings = settings; ShowToolTip = settings.ProgressBarShowToolTip; ShowTime = settings.ProgressBarShowTime; ProgressHltb_El1.Foreground = new SolidColorBrush(settings.ColorFirst); ProgressHltb_El2.Foreground = new SolidColorBrush(settings.ColorSecond); ProgressHltb_El3.Foreground = new SolidColorBrush(settings.ColorThird); if (_gameData != null && _gameData.hasData && !_gameData.isEmpty) { if (ShowToolTip) { PART_ShowToolTip.Visibility = Visibility.Visible; } else { PART_ShowToolTip.Visibility = Visibility.Collapsed; } LoadData(); } }
// To add new main menu items override GetMainMenuItems public override List <MainMenuItem> GetMainMenuItems(GetMainMenuItemsArgs args) { string MenuInExtensions = string.Empty; if (settings.MenuInExtensions) { MenuInExtensions = "@"; } List <MainMenuItem> mainMenuItems = new List <MainMenuItem> { new MainMenuItem { MenuSection = MenuInExtensions + resources.GetString("LOCHowLongToBeat"), Description = resources.GetString("LOCCommonGetAllDatas"), Action = (mainMenuItem) => { HowLongToBeatData.GetAllDataFromMain(PlayniteApi, this.GetPluginUserDataPath(), settings); } }, new MainMenuItem { MenuSection = MenuInExtensions + resources.GetString("LOCHowLongToBeat"), Description = resources.GetString("LOCCommonClearAllDatas"), Action = (mainMenuItem) => { HowLongToBeatData.ClearAllData(this.GetPluginUserDataPath(), PlayniteApi); } }, new MainMenuItem { MenuSection = MenuInExtensions + resources.GetString("LOCHowLongToBeat"), Description = resources.GetString("LOCCommonAddAllTags"), Action = (mainMenuItem) => { HowLongToBeatData.AddAllTagFromMain(PlayniteApi, this.GetPluginUserDataPath()); } }, new MainMenuItem { MenuSection = MenuInExtensions + resources.GetString("LOCHowLongToBeat"), Description = resources.GetString("LOCCommonRemoveAllTags"), Action = (mainMenuItem) => { HowLongToBeatData.RemoveAllTagFromMain(PlayniteApi, this.GetPluginUserDataPath()); } } }; #if DEBUG mainMenuItems.Add(new MainMenuItem { MenuSection = MenuInExtensions + resources.GetString("LOCHowLongToBeat"), Description = "Test", Action = (mainMenuItem) => { } }); #endif return(mainMenuItems); }
public override IEnumerable <ExtensionFunction> GetFunctions() { return(new List <ExtensionFunction> { new ExtensionFunction( resources.GetString("LOCHowLongToBeat"), () => { // Add code to be execute when user invokes this menu entry. try { HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath(), PlayniteApi); if (data.GetData() != null) { new Views.HowLongToBeat(data, GameSelected, PlayniteApi, settings).ShowDialog(); Integration(); } } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", "Error to load database"); PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "HowLongToBeat"); } }) }); }
/// <summary> /// Integration plugin interface in application. /// </summary> private void Integration() { try { // Delete logger.Info("HowLongToBeat - Delete"); ui.RemoveButtonInGameSelectedActionBarButtonOrToggleButton("PART_HltbButton"); ui.RemoveElementInGameSelectedDescription("PART_HltbProgressBarIntegration"); ui.ClearElementInCustomTheme("PART_hltbProgressBarWithTitle"); ui.ClearElementInCustomTheme("PART_hltbProgressBar"); HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath(), false); if (settings.EnableIntegrationButton) { Button HltbButton = new Button(); HltbButton.Name = "PART_HltbButton"; HltbButton.FontFamily = new FontFamily(new Uri("pack://application:,,,/HowLongToBeat;component/Resources/"), "./#font"); HltbButton.Margin = new Thickness(10, 0, 0, 0); HltbButton.Click += OnBtGameSelectedActionBarClick; HltbButton.Content = TransformIcon.Get("HowLongToBeat"); ui.AddButtonInGameSelectedActionBarButtonOrToggleButton(HltbButton); } // Auto integration if (settings.EnableIntegrationInDescription) { if (data.GetData() != null) { StackPanel spHltb = CreateHltb(GameSelected.Playtime, data.GetData(), settings.IntegrationShowTitle); spHltb.Name = "PART_HltbProgressBarIntegration"; ui.AddElementInGameSelectedDescription(spHltb, settings.IntegrationTopGameDetails); } } // Custom theme if (settings.EnableIntegrationInCustomTheme) { // Create StackPanel spHltb = CreateHltb(GameSelected.Playtime, data.GetData(), true); UserControl hltbProgressBar = new HltbProgressBar(GameSelected.Playtime, data.GetData()); ui.AddElementInCustomTheme(spHltb, "PART_hltbProgressBarWithTitle"); ui.AddElementInCustomTheme(hltbProgressBar, "PART_hltbProgressBar"); } } catch (Exception ex) { var LineNumber = new StackTrace(ex, true).GetFrame(0).GetFileLineNumber(); string FileName = new StackTrace(ex, true).GetFrame(0).GetFileName(); logger.Error(ex, $"HowLongToBeat [{FileName} {LineNumber}] - Impossible integration "); } }
private void OnBtGameSelectedActionBarClick(object sender, RoutedEventArgs e) { HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath()); if (data.GetData() != null) { new Views.HowLongToBeat(data, GameSelected, PlayniteApi).ShowDialog(); } }
// To add new game menu items override GetGameMenuItems public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args) { Game gameMenu = args.Games.First(); HowLongToBeatData data = new HowLongToBeatData(gameMenu, this.GetPluginUserDataPath(), PlayniteApi, false); List <GameMenuItem> gameMenuItems = new List <GameMenuItem> { new GameMenuItem { MenuSection = resources.GetString("LOCHowLongToBeat"), Description = resources.GetString("LOCHowLongToBeatPluginView"), Action = (gameMenuItem) => { try { if (!data.hasData) { data.SearchData(GameSelected); } if (data.hasData) { var ViewExtension = new HowLongToBeatView(data, gameMenu, PlayniteApi, settings); Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, "HowLongToBeat", ViewExtension); windowExtension.ShowDialog(); } } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", $"Error to load game data for {args.Games.First().Name}"); PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "HowLongToBeat"); } } }, new GameMenuItem { MenuSection = resources.GetString("LOCHowLongToBeat"), Description = resources.GetString("LOCCommonDeleteGameData"), Action = (gameMenuItem) => { data.RemoveData(); } } }; #if DEBUG gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCHowLongToBeat"), Description = "Test", Action = (mainMenuItem) => { } }); #endif return(gameMenuItems); }
private async Task <HowLongToBeatData> LoadData(IPlayniteAPI PlayniteApi, string PluginUserDataPath, HowLongToBeatSettings settings) { HowLongToBeatData HltbGameData = null; try { HltbGameData = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath(), PlayniteApi, false); } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", "Error to load data"); PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "HowLongToBeat"); } return(HltbGameData); }
private void OnBtGameSelectedActionBarClick(object sender, RoutedEventArgs e) { try { HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath(), PlayniteApi); if (data.GetData() != null) { new Views.HowLongToBeat(data, GameSelected, PlayniteApi, settings).ShowDialog(); Integration(); } } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", "Error to load data"); PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "HowLongToBeat"); } }
public override IEnumerable <ExtensionFunction> GetFunctions() { return(new List <ExtensionFunction> { new ExtensionFunction( "HowLongToBeat", () => { // Add code to be execute when user invokes this menu entry. HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath()); if (data.GetData() != null) { new Views.HowLongToBeat(data, GameSelected, PlayniteApi).ShowDialog(); } }) }); }
public HowLongToBeat(HowLongToBeatData data, Game game, IPlayniteAPI PlayniteApi) { this.data = data; InitializeComponent(); HltbDataUser gameData = data.GetData(); CoverImage = PlayniteApi.Database.GetFullFilePath(game.CoverImage); GameName = game.Name; int ElIndicator = 0; Hltb_El1.Visibility = System.Windows.Visibility.Hidden; Hltb_El1_Color.Visibility = System.Windows.Visibility.Hidden; Hltb_El2.Visibility = System.Windows.Visibility.Hidden; Hltb_El2_Color.Visibility = System.Windows.Visibility.Hidden; Hltb_El3.Visibility = System.Windows.Visibility.Hidden; Hltb_El3_Color.Visibility = System.Windows.Visibility.Hidden; if (gameData.GameHltbData.MainStory != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainStory"), gameData.GameHltbData.MainStoryFormat); } if (gameData.GameHltbData.MainExtra != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainExtra"), gameData.GameHltbData.MainExtraFormat); } if (gameData.GameHltbData.Completionist != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCompletionist"), gameData.GameHltbData.CompletionistFormat); } if (gameData.GameHltbData.Solo != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatSolo"), gameData.GameHltbData.SoloFormat); } if (gameData.GameHltbData.CoOp != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCoOp"), gameData.GameHltbData.CoOpFormat); } if (gameData.GameHltbData.Vs != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatVs"), gameData.GameHltbData.VsFormat); } LongToTimePlayedConverter converter = new LongToTimePlayedConverter(); PlaytimeFormat = (string)converter.Convert((long)game.Playtime, null, null, CultureInfo.CurrentCulture); HltbProgressBar.Children.Add(new HltbProgressBar(game.Playtime, gameData)); HltbProgressBar.UpdateLayout(); // Set Binding data DataContext = this; }
public HowLongToBeatView(HowLongToBeatData data, Game game, IPlayniteAPI PlayniteApi, HowLongToBeatSettings settings) { _data = data; InitializeComponent(); HltbDataUser gameData = data.GetData(); if (data.hasData && gameData != null && gameData.GameHltbData != null) { if (string.IsNullOrEmpty(game.CoverImage)) { CoverImage = gameData.GameHltbData.UrlImg; } else { CoverImage = gameData.GameHltbData.UrlImg; if (!settings.ShowHltbImg) { CoverImage = PlayniteApi.Database.GetFullFilePath(game.CoverImage); } } GameName = game.Name; HltbName = resources.GetString("LOCSourceLabel") + ": " + gameData.GameHltbData.Name; int ElIndicator = 0; Hltb_El1.Visibility = Visibility.Hidden; Hltb_El1_Color.Visibility = Visibility.Hidden; Hltb_El2.Visibility = Visibility.Hidden; Hltb_El2_Color.Visibility = Visibility.Hidden; Hltb_El3.Visibility = Visibility.Hidden; Hltb_El3_Color.Visibility = Visibility.Hidden; if (gameData.GameHltbData.MainStory != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainStory"), gameData.GameHltbData.MainStoryFormat); } if (gameData.GameHltbData.MainExtra != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainExtra"), gameData.GameHltbData.MainExtraFormat); } if (gameData.GameHltbData.Completionist != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCompletionist"), gameData.GameHltbData.CompletionistFormat); } if (gameData.GameHltbData.Solo != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatSolo"), gameData.GameHltbData.SoloFormat); } if (gameData.GameHltbData.CoOp != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCoOp"), gameData.GameHltbData.CoOpFormat); } if (gameData.GameHltbData.Vs != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatVs"), gameData.GameHltbData.VsFormat); } Hltb_El1_Color.Background = new SolidColorBrush(settings.ColorFirst); Hltb_El2_Color.Background = new SolidColorBrush(settings.ColorSecond); Hltb_El3_Color.Background = new SolidColorBrush(settings.ColorThird); LongToTimePlayedConverter converter = new LongToTimePlayedConverter(); PlaytimeFormat = (string)converter.Convert((long)game.Playtime, null, null, CultureInfo.CurrentCulture); if (!data.isEmpty) { HltbProgressBar hltbProgressBar = new HltbProgressBar(); hltbProgressBar.SetHltbData(game.Playtime, data, settings); PART_HltbProgressBar.Children.Add(hltbProgressBar); } } // Set Binding data DataContext = this; }
private void BtAddData_Click(object sender, RoutedEventArgs e) { bool AutoAccept = (bool)cbAutoAccept.IsChecked; bool ShowWhenMismatch = (bool)cbShowWhenMismatch.IsChecked; bool EnableTag = (bool)cbEnableTag.IsChecked; pbDataLoad.IsIndeterminate = false; pbDataLoad.Minimum = 0; pbDataLoad.Value = 0; pbDataLoad.Maximum = PlayniteApi.Database.Games.Count; DataLoad.Visibility = Visibility.Visible; spSettings.Visibility = Visibility.Hidden; tokenSource = new CancellationTokenSource(); ct = tokenSource.Token; int TotalAdded = 0; int TotalAlready = 0; int TotalMultiFind = 0; int TotlaNotFind = 0; var taskSystem = Task.Run(() => { ct.ThrowIfCancellationRequested(); foreach (Game game in PlayniteApi.Database.Games) { try { if (!HowLongToBeatData.HaveData(game.Id, PluginUserDataPath)) { List <HltbData> dataSearch = new HowLongToBeatClient().Search(game.Name); if (dataSearch.Count == 1 && AutoAccept) { HowLongToBeatData.SaveData(game.Id, dataSearch[0], PluginUserDataPath); if (EnableTag) { HowLongToBeatData.AddAllTag(PlayniteApi, game, PluginUserDataPath); } TotalAdded += 1; } else { TotalMultiFind += 1; if (dataSearch.Count > 0 && ShowWhenMismatch) { Application.Current.Dispatcher.Invoke(new Action(() => { string FileGameData = PluginUserDataPath + "\\howlongtobeat\\" + game.Id.ToString() + ".json"; new HowLongToBeatSelect(dataSearch, FileGameData, game.Name).ShowDialog(); if (EnableTag) { HowLongToBeatData.AddAllTag(PlayniteApi, game, PluginUserDataPath); } })); } else { TotlaNotFind += 1; } } } else { TotalAlready += 1; logger.Debug($"HowLongToBeat - {game.Name}"); } Application.Current.Dispatcher.Invoke(new Action(() => { tbDataLoad.Text = string.Format(resources.GetString("LOCHowLongToBeatProgressBar"), TotalAdded, TotalAlready, TotlaNotFind); pbDataLoad.Value += 1; })); } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", $"Error on BtAddData_Click()"); } if (ct.IsCancellationRequested) { ct.ThrowIfCancellationRequested(); } } }, tokenSource.Token) .ContinueWith(antecedent => { Application.Current.Dispatcher.Invoke(new Action(() => { DataLoad.Visibility = Visibility.Collapsed; spSettings.Visibility = Visibility.Visible; })); }); }
/// <summary> /// Integration plugin interface in application. /// </summary> private void Integration(Game game = null) { try { if (game != null) { GameSelected = game; } // Delete logger.Info("HowLongToBeat - Delete integeration"); ui.RemoveButtonInGameSelectedActionBarButtonOrToggleButton("PART_HltbButton"); ui.RemoveElementInGameSelectedDescription("PART_HltbProgressBarIntegration"); ui.ClearElementInCustomTheme("PART_hltbProgressBarWithTitle"); ui.ClearElementInCustomTheme("PART_hltbProgressBar"); // Reset resources List <ResourcesList> resourcesLists = new List <ResourcesList>(); resourcesLists.Add(new ResourcesList { Key = "Htlb_HasData", Value = false }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainStory", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainStoryFormat", Value = "" }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainExtra", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainExtraFormat", Value = "" }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Completionist", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CompletionistFormat", Value = "" }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Solo", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_SoloFormat", Value = "" }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CoOp", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CoOpFormat", Value = "" }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Vs", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_VsFormat", Value = "" }); ui.AddResources(resourcesLists); var taskIntegration = Task.Run(() => LoadData(PlayniteApi, this.GetPluginUserDataPath(), settings)) .ContinueWith(antecedent => { HowLongToBeatData HltbGameData = antecedent.Result; Application.Current.Dispatcher.Invoke(new Action(() => { if (HltbGameData.hasData) { // Add resources resourcesLists = new List <ResourcesList>(); resourcesLists.Add(new ResourcesList { Key = "Htlb_HasData", Value = HltbGameData.hasData }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainStory", Value = HltbGameData.GetData().GameHltbData.MainStory }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainStoryFormat", Value = HltbGameData.GetData().GameHltbData.MainStoryFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainExtra", Value = HltbGameData.GetData().GameHltbData.MainExtra }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainExtraFormat", Value = HltbGameData.GetData().GameHltbData.MainExtraFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Completionist", Value = HltbGameData.GetData().GameHltbData.Completionist }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CompletionistFormat", Value = HltbGameData.GetData().GameHltbData.CompletionistFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Solo", Value = HltbGameData.GetData().GameHltbData.Solo }); resourcesLists.Add(new ResourcesList { Key = "Htlb_SoloFormat", Value = HltbGameData.GetData().GameHltbData.SoloFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CoOp", Value = HltbGameData.GetData().GameHltbData.CoOp }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CoOpFormat", Value = HltbGameData.GetData().GameHltbData.CoOpFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Vs", Value = HltbGameData.GetData().GameHltbData.Vs }); resourcesLists.Add(new ResourcesList { Key = "Htlb_VsFormat", Value = HltbGameData.GetData().GameHltbData.VsFormat }); ui.AddResources(resourcesLists); // Add button in action bar if (settings.EnableIntegrationButton) { Button HltbButton = new Button(); HltbButton.Name = "PART_HltbButton"; HltbButton.FontFamily = new FontFamily(new Uri("pack://application:,,,/HowLongToBeat;component/Resources/"), "./#font"); HltbButton.Margin = new Thickness(10, 0, 0, 0); HltbButton.Click += OnBtGameSelectedActionBarClick; HltbButton.Content = TransformIcon.Get("HowLongToBeat"); ui.AddButtonInGameSelectedActionBarButtonOrToggleButton(HltbButton); } // Auto integration if (settings.EnableIntegrationInDescription) { StackPanel spHltb = CreateHltb(GameSelected.Playtime, HltbGameData.GetData(), settings.IntegrationShowTitle); spHltb.Name = "PART_HltbProgressBarIntegration"; ui.AddElementInGameSelectedDescription(spHltb, settings.IntegrationTopGameDetails); } // Custom theme if (settings.EnableIntegrationInCustomTheme) { // Create StackPanel spHltb = CreateHltb(GameSelected.Playtime, HltbGameData.GetData(), true); UserControl hltbProgressBar = new HltbProgressBar(GameSelected.Playtime, HltbGameData.GetData(), settings); ui.AddElementInCustomTheme(spHltb, "PART_hltbProgressBarWithTitle"); ui.AddElementInCustomTheme(hltbProgressBar, "PART_hltbProgressBar"); } } })); }); } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", "Impossible integration"); } }
public void SetHltbData(long Playtime, HowLongToBeatData data, HowLongToBeatSettings settings) { hltbProgressBar.SetHltbData(Playtime, data, settings); PART_HltbProgressBar.UpdateLayout(); }