/// <summary> /// Create the StackPanel with the ProgressBar. /// </summary> /// <param name="Playtime"></param> /// <param name="data"></param> /// <returns></returns> private StackPanel CreateHltb(long Playtime, HltbDataUser data, bool IntegrationShowTitle) { StackPanel spHltb = new StackPanel(); TextBlock tbHltb = new TextBlock(); Separator hltbsep = new Separator(); if (IntegrationShowTitle) { tbHltb.Name = "PART_tbHltb"; tbHltb.Text = resources.GetString("LOCHowLongToBeatTitle"); tbHltb.Style = (Style)resources.GetResource("BaseTextBlockStyle"); tbHltb.Margin = new Thickness(0, 15, 0, 10); hltbsep.Name = "PART_hltbsep"; hltbsep.Background = (Brush)resources.GetResource("PanelSeparatorBrush"); } UserControl hltbProgressBar = new HltbProgressBar(Playtime, data); hltbProgressBar.Name = "PART_hltbProgressBar"; hltbProgressBar.Margin = new Thickness(0, 5, 0, 5); if (IntegrationShowTitle) { spHltb.Children.Add(tbHltb); spHltb.Children.Add(hltbsep); } spHltb.Children.Add(hltbProgressBar); spHltb.UpdateLayout(); return(spHltb); }
/// <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 "); } }
public override void AddCustomElements() { if (ListCustomElements.Count > 0) { #if DEBUG logger.Debug($"HowLongToBeat [Ignored] - CustomElements allready insert - {ListCustomElements.Count}"); #endif return; } FrameworkElement PART_HltbButtonWithJustIcon = null; FrameworkElement PART_hltbProgressBar = null; try { PART_HltbButtonWithJustIcon = IntegrationUI.SearchElementByName("PART_HltbButtonWithJustIcon", false, true); PART_hltbProgressBar = IntegrationUI.SearchElementByName("PART_hltbProgressBar", false, true); } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", $"Error on find custom element"); } if (PART_HltbButtonWithJustIcon != null) { PART_HltbButtonWithJustIcon = new HltbButton(); PART_HltbButtonWithJustIcon.Name = "HltbButtonWithJustIcon"; ((Button)PART_HltbButtonWithJustIcon).Click += OnBtActionBarClick; try { ui.AddElementInCustomTheme(PART_HltbButtonWithJustIcon, "PART_HltbButtonWithJustIcon"); ListCustomElements.Add(new CustomElement { ParentElementName = "PART_HltbButtonWithJustIcon", Element = PART_HltbButtonWithJustIcon }); } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", "Error on AddCustomElements()"); } } else { #if DEBUG logger.Debug($"HowLongToBeat [Ignored] - PART_HltbButtonWithJustIcon not find"); #endif } if (PART_hltbProgressBar != null) { PART_hltbProgressBar = new HltbProgressBar(); PART_hltbProgressBar.Name = "hltbProgressBar"; try { ui.AddElementInCustomTheme(PART_hltbProgressBar, "PART_hltbProgressBar"); ListCustomElements.Add(new CustomElement { ParentElementName = "PART_hltbProgressBar", Element = PART_hltbProgressBar }); } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", "Error on AddCustomElements()"); } } else { #if DEBUG logger.Debug($"HowLongToBeat [Ignored] - PART_HltbButtonWithJustIcon not find"); #endif } }
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; }
public HowLongToBeatView(IPlayniteAPI PlayniteApi, HowLongToBeatSettings settings, GameHowLongToBeat gameHowLongToBeat) { _gameHowLongToBeat = gameHowLongToBeat; InitializeComponent(); HltbDataUser gameData = _gameHowLongToBeat.Items.FirstOrDefault(); if (gameData == null) { return; } if (_gameHowLongToBeat.HasData || _gameHowLongToBeat.HasDataEmpty) { CoverImage = gameData.UrlImg; if (!settings.ShowHltbImg) { if (!_gameHowLongToBeat.CoverImage.IsNullOrEmpty()) { CoverImage = PlayniteApi.Database.GetFullFilePath(_gameHowLongToBeat.CoverImage); } } GameName = _gameHowLongToBeat.Name; HltbName = resources.GetString("LOCSourceLabel") + ": " + gameData.Name; } if (_gameHowLongToBeat.HasData) { 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; TitleList titleList = PluginDatabase.GetUserHltbData(_gameHowLongToBeat.GetData().Id); if (gameData.GameHltbData.MainStory != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainStory"), gameData.GameHltbData.MainStoryFormat, (titleList != null) ? titleList.HltbUserData.MainStoryFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorFirst); } if (gameData.GameHltbData.MainExtra != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainExtra"), gameData.GameHltbData.MainExtraFormat, (titleList != null) ? titleList.HltbUserData.MainExtraFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorSecond); } if (gameData.GameHltbData.Completionist != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCompletionist"), gameData.GameHltbData.CompletionistFormat, (titleList != null) ? titleList.HltbUserData.CompletionistFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorThird); } if (gameData.GameHltbData.Solo != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatSolo"), gameData.GameHltbData.SoloFormat, (titleList != null) ? titleList.HltbUserData.SoloFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorFirstMulti); } if (gameData.GameHltbData.CoOp != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCoOp"), gameData.GameHltbData.CoOpFormat, (titleList != null) ? titleList.HltbUserData.CoOpFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorSecondMulti); } if (gameData.GameHltbData.Vs != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatVs"), gameData.GameHltbData.VsFormat, (titleList != null) ? titleList.HltbUserData.VsFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorThirdMulti); } LongToTimePlayedConverter converter = new LongToTimePlayedConverter(); PlaytimeFormat = (string)converter.Convert((long)_gameHowLongToBeat.Playtime, null, null, CultureInfo.CurrentCulture); hltbProgressBar = new HltbProgressBar(); PART_HltbProgressBar.Children.Add(hltbProgressBar); } // Set Binding data DataContext = this; }
/// <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"); } }