public override void AddBtActionBar() { if (PART_BtActionBar != null) { #if DEBUG logger.Debug($"SuccessStory - PART_BtActionBar allready insert"); #endif return; } FrameworkElement BtActionBar; if (_Settings.EnableIntegrationInDescriptionWithToggle) { if (_Settings.EnableIntegrationButtonDetails) { BtActionBar = new SuccessStoryToggleButtonDetails(); } else { BtActionBar = new SuccessStoryToggleButton(_Settings); } ((ToggleButton)BtActionBar).Click += OnBtActionBarToggleButtonClick; } else { if (_Settings.EnableIntegrationButtonDetails) { BtActionBar = new SuccessStoryButtonDetails(); } else { BtActionBar = new SuccessStoryButton(_Settings.EnableIntegrationInDescriptionOnlyIcon); } ((Button)BtActionBar).Click += OnBtActionBarClick; } if (!_Settings.EnableIntegrationInDescriptionOnlyIcon) { BtActionBar.Width = 150; } BtActionBar.Name = BtActionBarName; BtActionBar.Margin = new Thickness(10, 0, 0, 0); try { ui.AddButtonInGameSelectedActionBarButtonOrToggleButton(BtActionBar); PART_BtActionBar = IntegrationUI.SearchElementByName(BtActionBarName); } catch (Exception ex) { Common.LogError(ex, "SuccessStory", "Error on AddBtActionBar()"); } }
private void Integration() { try { // Search game description if (PART_ElemDescription == null) { foreach (StackPanel sp in Tools.FindVisualChildren <StackPanel>(Application.Current.MainWindow)) { if (sp.Name == "PART_ElemDescription") { PART_ElemDescription = sp; break; } } } // Delete logger.Info("SuccessStory - Delete"); ui.RemoveButtonInGameSelectedActionBarButtonOrToggleButton("PART_ScButton"); ui.RemoveButtonInGameSelectedActionBarButtonOrToggleButton("PART_ScToggleButton"); ui.RemoveElementInGameSelectedDescription("PART_Achievements"); ui.ClearElementInCustomTheme("PART_Achievements_Graphics"); ui.ClearElementInCustomTheme("PART_Achievements_List"); ui.ClearElementInCustomTheme("PART_Achievements_ProgressBar"); // Reset resources List <ResourcesList> resourcesLists = new List <ResourcesList>(); resourcesLists.Add(new ResourcesList { Key = "Sc_Total", Value = "0" }); resourcesLists.Add(new ResourcesList { Key = "Sc_Unlocked", Value = "0" }); resourcesLists.Add(new ResourcesList { Key = "Sc_Locked", Value = "0" }); ui.AddResources(resourcesLists); var taskIntegration = Task.Run(() => LoadData(PlayniteApi, this.GetPluginUserDataPath(), settings)) .ContinueWith(antecedent => { GameAchievements SelectedGameAchievements = antecedent.Result; Application.Current.Dispatcher.Invoke(new Action(() => { // No achievements if (SelectedGameAchievements == null || !SelectedGameAchievements.HaveAchivements) { //logger.Debug(JsonConvert.SerializeObject(SelectedGameAchievements)); logger.Info("SuccessStory - No achievement for " + GameSelected.Name); return; } // Add resources resourcesLists.Add(new ResourcesList { Key = "Sc_Total", Value = SelectedGameAchievements.Total.ToString() }); resourcesLists.Add(new ResourcesList { Key = "Sc_Unlocked", Value = SelectedGameAchievements.Unlocked.ToString() }); resourcesLists.Add(new ResourcesList { Key = "Sc_Locked", Value = SelectedGameAchievements.Locked.ToString() }); ui.AddResources(resourcesLists); // Auto integration if (settings.EnableIntegrationInDescription || settings.EnableIntegrationInDescriptionWithToggle) { if (settings.EnableIntegrationInDescriptionWithToggle) { ToggleButton tb = new ToggleButton(); if (settings.IntegrationToggleDetails) { tb = new SuccessStoryToggleButtonDetails(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total); } else { tb = new SuccessStoryToggleButton(); tb.Content = resources.GetString("LOCSucessStoryAchievements"); } tb.IsChecked = false; tb.Name = "PART_ScToggleButton"; tb.Width = 150; tb.HorizontalAlignment = HorizontalAlignment.Right; tb.VerticalAlignment = VerticalAlignment.Stretch; tb.Margin = new Thickness(10, 0, 0, 0); tb.Click += OnGameSelectedToggleButtonClick; ui.AddButtonInGameSelectedActionBarButtonOrToggleButton(tb); } // Add Achievements elements StackPanel ScA = CreateSc(achievementsDatabase, SelectedGameAchievements, settings.IntegrationShowTitle, settings.IntegrationShowGraphic, settings.IntegrationShowAchievements, settings.IntegrationShowProgressBar, false); if (settings.EnableIntegrationInDescriptionWithToggle) { ScA.Visibility = Visibility.Collapsed; } ui.AddElementInGameSelectedDescription(ScA, settings.IntegrationTopGameDetails); } // Auto adding button if (settings.EnableIntegrationButton || settings.EnableIntegrationButtonDetails) { Button bt = new Button(); if (settings.EnableIntegrationButton) { bt.Content = resources.GetString("LOCSucessStoryAchievements"); } if (settings.EnableIntegrationButtonDetails) { bt = new SuccessStoryButtonDetails(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total); } bt.Name = "PART_ScButton"; bt.Width = 150; bt.HorizontalAlignment = HorizontalAlignment.Right; bt.VerticalAlignment = VerticalAlignment.Stretch; bt.Margin = new Thickness(10, 0, 0, 0); bt.Click += OnBtGameSelectedActionBarClick; ui.AddButtonInGameSelectedActionBarButtonOrToggleButton(bt); } // Custom theme if (settings.EnableIntegrationInCustomTheme) { if (settings.IntegrationShowGraphic) { StackPanel scAG = CreateSc(achievementsDatabase, SelectedGameAchievements, false, true, false, false, true); ui.AddElementInCustomTheme(scAG, "PART_Achievements_Graphics"); } if (settings.IntegrationShowAchievements) { StackPanel scAL = CreateSc(achievementsDatabase, SelectedGameAchievements, false, false, true, false, true); ui.AddElementInCustomTheme(scAL, "PART_Achievements_List"); } if (settings.IntegrationShowProgressBar) { StackPanel scPB = CreateSc(achievementsDatabase, SelectedGameAchievements, false, false, false, true, true); ui.AddElementInCustomTheme(scPB, "PART_Achievements_ProgressBar"); } } })); }); } catch (Exception ex) { Common.LogError(ex, "SucessStory", $"Impossible integration"); } }
private void Integration() { bool noAchievements = false; try { AchievementsDatabase achievementsDatabase = new AchievementsDatabase(PlayniteApi, this.GetPluginUserDataPath()); achievementsDatabase.Initialize(); GameAchievements SelectedGameAchievements = achievementsDatabase.Get(GameSelected.Id); // Download Achievements if not exist in database. if (SelectedGameAchievements == null) { logger.Info("SuccesStory - Download achievements for " + GameSelected.Name); achievementsDatabase.Add(GameSelected, settings); achievementsDatabase.Initialize(); SelectedGameAchievements = achievementsDatabase.Get(GameSelected.Id); } if (SelectedGameAchievements == null || !SelectedGameAchievements.HaveAchivements) { logger.Info("SuccessStory - No achievement for " + GameSelected.Name); if (settings.EnableIntegrationInDescription || settings.EnableIntegrationInDescriptionWithToggle) { Button PART_ScButton = (Button)LogicalTreeHelper.FindLogicalNode(PART_ActionButtons, "PART_ScButton"); // Delete old ButtonDetails if (settings.EnableIntegrationButtonDetails) { PART_ActionButtons.Children.Remove(PART_ScButton); PART_ScButton = null; } ToggleButton PART_ScToggleButton = (ToggleButton)LogicalTreeHelper.FindLogicalNode(PART_ActionButtons, "PART_ScToggleButton"); // Delete old ToggleDetails if (settings.IntegrationToggleDetails) { PART_ActionButtons.Children.Remove(PART_ScToggleButton); PART_ScToggleButton = null; } // Delete old string NameControl = "PART_Achievements"; StackPanel PART_Achievements = (StackPanel)LogicalTreeHelper.FindLogicalNode(PART_ElemDescription, NameControl); if (PART_Achievements != null) { PART_ElemDescription.Children.Remove(PART_Achievements); } } noAchievements = true; } // Auto integration if (settings.EnableIntegrationInDescription || settings.EnableIntegrationInDescriptionWithToggle) { // Search parent action buttons if (PART_ActionButtons == null) { foreach (Button bt in Tools.FindVisualChildren <Button>(Application.Current.MainWindow)) { if (bt.Name == "PART_ButtonEditGame") { PART_ActionButtons = (StackPanel)bt.Parent; break; } } } //Adding togglebutton if (settings.EnableIntegrationInDescriptionWithToggle && PART_ActionButtons != null) { ToggleButton PART_ScToggleButton = (ToggleButton)LogicalTreeHelper.FindLogicalNode(PART_ActionButtons, "PART_ScToggleButton"); // Delete old ToggleDetails if (settings.IntegrationToggleDetails) { PART_ActionButtons.Children.Remove(PART_ScToggleButton); PART_ScToggleButton = null; } if (PART_ScToggleButton == null && !noAchievements) { ToggleButton tb = new ToggleButton(); if (settings.IntegrationToggleDetails) { tb = new SuccessStoryToggleButtonDetails(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total); } else { tb.Content = resources.GetString("LOCSucessStoryAchievements"); } tb.IsChecked = false; tb.Name = "PART_ScToggleButton"; tb.Width = 150; tb.Height = 40; tb.HorizontalAlignment = HorizontalAlignment.Right; tb.VerticalAlignment = VerticalAlignment.Stretch; tb.Margin = new Thickness(10, 0, 0, 0); tb.Click += ScToggleButton_Click; PART_ActionButtons.Children.Add(tb); PART_ActionButtons.UpdateLayout(); } } // Search game description if (PART_ElemDescription == null) { foreach (StackPanel sp in Tools.FindVisualChildren <StackPanel>(Application.Current.MainWindow)) { if (sp.Name == "PART_ElemDescription") { PART_ElemDescription = sp; break; } } } // Adding control if (PART_ElemDescription != null) { // Delete old string NameControl = "PART_Achievements"; StackPanel PART_Achievements = (StackPanel)LogicalTreeHelper.FindLogicalNode(PART_ElemDescription, NameControl); if (PART_Achievements != null) { if (settings.EnableIntegrationInDescription) { PART_ElemDescription.Children.Remove(PART_Achievements); } if (settings.EnableIntegrationInDescriptionWithToggle) { PART_ElemDescription.Children.Remove(PART_Achievements); } } else { logger.Error($"SuccessStory - {NameControl} not found in Integration()"); } if (SelectedGameAchievements != null && SelectedGameAchievements.HaveAchivements) { StackPanel ScA = CreateSc(achievementsDatabase, SelectedGameAchievements, settings.IntegrationShowTitle, settings.IntegrationShowGraphic, settings.IntegrationShowAchievements, false); if (settings.EnableIntegrationInDescription) { // Add if (settings.IntegrationTopGameDetails) { PART_ElemDescription.Children.Insert(0, ScA); } else { PART_ElemDescription.Children.Add(ScA); } PART_ElemDescription.UpdateLayout(); } if (settings.EnableIntegrationInDescriptionWithToggle) { ScA.Visibility = Visibility.Collapsed; PART_ElemDescription.Children.Add(ScA); PART_ElemDescription.UpdateLayout(); } } } else { logger.Error($"SuccessStory - PART_ElemDescription not found in Integration()"); } } // Auto adding button if (settings.EnableIntegrationButton || settings.EnableIntegrationButtonDetails) { // Search parent action buttons if (PART_ActionButtons == null) { foreach (Button bt in Tools.FindVisualChildren <Button>(Application.Current.MainWindow)) { if (bt.Name == "PART_ButtonEditGame") { PART_ActionButtons = (StackPanel)bt.Parent; break; } } } // Adding button if (PART_ActionButtons != null) { Button PART_ScButton = (Button)LogicalTreeHelper.FindLogicalNode(PART_ActionButtons, "PART_ScButton"); // Delete old ButtonDetails if (settings.EnableIntegrationButtonDetails) { PART_ActionButtons.Children.Remove(PART_ScButton); PART_ScButton = null; } if (PART_ScButton == null) { Button bt = new Button(); if (settings.EnableIntegrationButton) { bt.Content = resources.GetString("LOCSucessStoryAchievements"); } if (settings.EnableIntegrationButtonDetails) { bt = new SuccessStoryButtonDetails(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total); } bt.Name = "PART_ScButton"; bt.Width = 150; bt.Height = 40; bt.HorizontalAlignment = HorizontalAlignment.Right; bt.VerticalAlignment = VerticalAlignment.Stretch; bt.Margin = new Thickness(10, 0, 0, 0); bt.Click += ScButton_Click; PART_ActionButtons.Children.Add(bt); PART_ActionButtons.UpdateLayout(); } } } // Custom theme if (settings.EnableIntegrationInCustomTheme) { // Search custom element foreach (StackPanel sp in Tools.FindVisualChildren <StackPanel>(Application.Current.MainWindow)) { if (sp.Name == "PART_Achievements_Graphics") { if (SelectedGameAchievements != null && SelectedGameAchievements.HaveAchivements) { // Create StackPanel scAG = CreateSc(achievementsDatabase, SelectedGameAchievements, false, true, false, true); // Clear & add sp.Children.Clear(); sp.Children.Add(scAG); sp.UpdateLayout(); } else { sp.Children.Clear(); sp.UpdateLayout(); } } if (sp.Name == "PART_Achievements_List") { if (SelectedGameAchievements != null && SelectedGameAchievements.HaveAchivements) { // Create StackPanel scAL = CreateSc(achievementsDatabase, SelectedGameAchievements, false, false, true, true); // Clear & add sp.Children.Clear(); sp.Children.Add(scAL); sp.UpdateLayout(); } else { sp.Children.Clear(); sp.UpdateLayout(); } } } } } catch (Exception ex) { var LineNumber = new StackTrace(ex, true).GetFrame(0).GetFileLineNumber(); string FileName = new StackTrace(ex, true).GetFrame(0).GetFileName(); logger.Error(ex, $"SuccessStory [{FileName} {LineNumber}] - Impossible integration "); } }