/// <summary> /// Show Achievements for the selected game. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ListviewGames_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListViewGames GameSelected = (ListViewGames)((ListBox)sender).SelectedItem; if (GameSelected != null) { listAchievementBorder.BorderThickness = new Thickness(0); Guid GameId = Guid.Parse(GameSelected.Id); GameAchievements GameAchievements = AchievementsDb.Get(GameId); List <Achievements> ListAchievements = GameAchievements.Achievements; SuccessStory_Achievements_List.Children.Clear(); SuccessStoryAchievementsList successStoryAchievementsList = new SuccessStoryAchievementsList(); successStoryAchievementsList.SetScData(ListAchievements, false, settings.EnableRaretyIndicator); SuccessStory_Achievements_List.Children.Add(successStoryAchievementsList); SuccessStory_Achievements_List.UpdateLayout(); AchievementsGraphicsDataCount GraphicsData = null; if (settings.GraphicAllUnlockedByDay) { GraphicTitle.Content = resources.GetString("LOCSuccessStoryGraphicTitle"); GraphicsData = AchievementsDb.GetCountByMonth(GameId); } else { GraphicTitle.Content = resources.GetString("LOCSuccessStoryGraphicTitleDay"); GraphicsData = AchievementsDb.GetCountByDay(GameId, 8); } string[] StatsGraphicsAchievementsLabels = GraphicsData.Labels; SeriesCollection StatsGraphicAchievementsSeries = new SeriesCollection(); StatsGraphicAchievementsSeries.Add(new LineSeries { Title = string.Empty, Values = GraphicsData.Series }); SuccessStory_Achievements_Graphics_Game.Children.Clear(); settings.IgnoreSettings = true; SuccessStory_Achievements_Graphics_Game.Children.Add(new SuccessStoryAchievementsGraphics(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels, settings)); SuccessStory_Achievements_Graphics_Game.UpdateLayout(); GC.Collect(); } }
// Create FrameworkElement with achievements datas public StackPanel CreateSc(AchievementsDatabase achievementsDatabase, GameAchievements SelectedGameAchievements, bool ShowTitle, bool ShowGraphic, bool ShowAchievements, bool ShowProgressBar, bool IsCustom = false) { StackPanel spA = new StackPanel(); spA.Name = "PART_Achievements"; if (ShowTitle) { TextBlock tbA = new TextBlock(); tbA.Name = "PART_Achievements_TextBlock"; tbA.Text = resources.GetString("LOCSucessStoryAchievements"); tbA.Style = (Style)resources.GetResource("BaseTextBlockStyle"); tbA.Margin = new Thickness(0, 15, 0, 10); Separator sep = new Separator(); sep.Name = "PART_Achievements_Separator"; sep.Background = (Brush)resources.GetResource("PanelSeparatorBrush"); spA.Children.Add(tbA); spA.Children.Add(sep); spA.UpdateLayout(); } if (ShowGraphic) { StackPanel spAG = new StackPanel(); if (!IsCustom) { spAG.Name = "PART_Achievements_Graphics"; spAG.Height = 120; spAG.MaxHeight = 120; spAG.Margin = new Thickness(0, 5, 0, 5); } AchievementsGraphicsDataCount GraphicsData = null; if (settings.GraphicAllUnlockedByDay) { GraphicsData = achievementsDatabase.GetCountByMonth(GameSelected.Id); } else { GraphicsData = achievementsDatabase.GetCountByDay(GameSelected.Id); } string[] StatsGraphicsAchievementsLabels = GraphicsData.Labels; SeriesCollection StatsGraphicAchievementsSeries = new SeriesCollection(); StatsGraphicAchievementsSeries.Add(new LineSeries { Title = "", Values = GraphicsData.Series }); spAG.Children.Add(new SuccessStoryAchievementsGraphics(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels)); spA.Children.Add(spAG); spA.UpdateLayout(); } if (ShowProgressBar) { StackPanel spPB = new StackPanel(); if (!IsCustom) { spPB.Name = "PART_Achievements_ProgressBar"; spPB.Height = 40; spPB.Margin = new Thickness(0, 5, 0, 5); } spPB.Children.Add(new SuccessStoryAchievementsProgressBar(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total, settings.IntegrationShowProgressBarPercent, settings.IntegrationShowProgressBarIndicator)); spA.Children.Add(spPB); spA.UpdateLayout(); } if (ShowAchievements) { StackPanel spAL = new StackPanel(); if (!IsCustom) { spAL.Name = "PART_Achievements_List"; spAL.MaxHeight = 300; spAL.Margin = new Thickness(0, 5, 0, 5); } spAL.Children.Add(new SuccessStoryAchievementsList(SelectedGameAchievements.Achievements)); spA.Children.Add(spAL); spA.UpdateLayout(); } return(spA); }
public SuccessView(SuccessStorySettings settings, IPlayniteAPI PlayniteApi, string PluginUserDataPath, Game GameSelected = null) { this.PlayniteApi = PlayniteApi; PlayniteApiDatabase = PlayniteApi.Database; PlayniteApiPaths = PlayniteApi.Paths; this.settings = settings; this.PluginUserDataPath = PluginUserDataPath; AchievementsDatabase = new AchievementsDatabase(PlayniteApi, settings, PluginUserDataPath); AchievementsDatabase.Initialize(); InitializeComponent(); // Block hidden column. lvProgressionValue.IsEnabled = false; lvSourceName.IsEnabled = false; pbProgressionGlobalCount.Value = AchievementsDatabase.Progession().Unlocked; pbProgressionGlobalCount.Maximum = AchievementsDatabase.Progession().Total; labelProgressionGlobalCount.Content = AchievementsDatabase.Progession().Progression + "%"; pbProgressionLaunchedCount.Value = AchievementsDatabase.ProgessionLaunched().Unlocked; pbProgressionLaunchedCount.Maximum = AchievementsDatabase.ProgessionLaunched().Total; labelProgressionLaunchedCount.Content = AchievementsDatabase.ProgessionLaunched().Progression + "%"; GetListGame(); AchievementsGraphicsDataCount GraphicsData = null; if (settings.GraphicAllUnlockedByMonth) { GraphicTitleALL.Content = resources.GetString("LOCSucessStoryGraphicTitleALL"); GraphicsData = AchievementsDatabase.GetCountByMonth(null, 7); } else { GraphicTitleALL.Content = resources.GetString("LOCSucessStoryGraphicTitleALLDay"); GraphicsData = AchievementsDatabase.GetCountByDay(); } string[] StatsGraphicsAchievementsLabels = GraphicsData.Labels; SeriesCollection StatsGraphicAchievementsSeries = new SeriesCollection(); StatsGraphicAchievementsSeries.Add(new LineSeries { Title = "", Values = GraphicsData.Series }); SuccessStory_Achievements_Graphics.Children.Clear(); SuccessStory_Achievements_Graphics.Children.Add(new SuccessStoryAchievementsGraphics(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels)); SuccessStory_Achievements_Graphics.UpdateLayout(); // Set game selected if (GameSelected != null) { for (int i = 0; i < ListviewGames.Items.Count; i++) { if (((ListGames)ListviewGames.Items[i]).Name == GameSelected.Name) { ListviewGames.SelectedIndex = i; } } } ListviewGames.ScrollIntoView(ListviewGames.SelectedItem); if (settings.EnableLocal) { //FilterSource.Items.Add(new { SourceName = "Playnite", IsCheck = false }); FilterSourceItems.Add(new ListSource { SourceName = "Playnite", IsCheck = false }); } if (settings.EnableSteam) { //FilterSource.Items.Add(new { SourceName = "Steam", IsCheck = false }); FilterSourceItems.Add(new ListSource { SourceName = "Steam", IsCheck = false }); } if (settings.EnableGog) { //FilterSource.Items.Add(new { SourceName = "GOG", IsCheck = false }); FilterSourceItems.Add(new ListSource { SourceName = "GOG", IsCheck = false }); } if (settings.EnableOrigin) { //FilterSource.Items.Add(new { SourceName = "Origin", IsCheck = false }); FilterSourceItems.Add(new ListSource { SourceName = "Origin", IsCheck = false }); } if (settings.EnableOrigin) { //FilterSource.Items.Add(new { SourceName = "Origin", IsCheck = false }); FilterSourceItems.Add(new ListSource { SourceName = "RetroAchievements", IsCheck = false }); } //FilterSource.UpdateLayout(); FilterSource.ItemsSource = FilterSourceItems; SetGraphicsAchievementsSources(); // Set Binding data DataContext = this; }
public void SetScData(SuccessStorySettings settings, AchievementsDatabase achievementsDatabase, GameAchievements SelectedGameAchievements) { if (!settings.IntegrationShowTitle || _IsCustom) { PART_Title.Visibility = Visibility.Collapsed; PART_Separator.Visibility = Visibility.Collapsed; } #if DEBUG logger.Debug($"SuccessStory - _IsCustom: {_IsCustom} - _ShowAchievementsGraphic: {_ShowAchievementsGraphic} - _ShowAchievementsList: {_ShowAchievementsList} - _ShowAchievementsCompactLocked: {_ShowAchievementsCompactLocked} - _ShowAchievementsCompactUnlocked: {_ShowAchievementsCompactUnlocked} - _ShowProgressBar: {_ShowProgressBar}"); #endif bool Show = true; if (SelectedGameAchievements == null || !SelectedGameAchievements.HaveAchivements) { return; } PART_SuccessStory_ProgressBar.Visibility = Visibility.Collapsed; if (settings.IntegrationShowProgressBar) { Show = true; if (_IsCustom && !_ShowProgressBar) { Show = false; } #if DEBUG logger.Debug($"SuccessStory - PART_SuccessStory_ProgressBar - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}"); #endif if (Show) { PART_SuccessStory_ProgressBar.Visibility = Visibility.Visible; if (successStoryAchievementsProgressBar == null) { successStoryAchievementsProgressBar = new SuccessStoryAchievementsProgressBar(); if (!_IsCustom) { PART_SuccessStory_ProgressBar.Height = 40; PART_SuccessStory_ProgressBar.Margin = new Thickness(0, 5, 0, 5); } PART_SuccessStory_ProgressBar.Children.Add(successStoryAchievementsProgressBar); } successStoryAchievementsProgressBar.SetScData(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total, settings.IntegrationShowProgressBarPercent, settings.IntegrationShowProgressBarIndicator, _IsCustom); } } PART_SuccessStory_Graphic.Visibility = Visibility.Collapsed; if (settings.IntegrationShowGraphic) { Show = true; if (_IsCustom && !_ShowAchievementsGraphic) { Show = false; } #if DEBUG logger.Debug($"SuccessStory - PART_SuccessStory_Graphic - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}"); #endif if (Show) { PART_SuccessStory_Graphic.Visibility = Visibility.Visible; AchievementsGraphicsDataCount GraphicsData = null; if (!settings.GraphicAllUnlockedByDay) { GraphicsData = achievementsDatabase.GetCountByMonth(SuccessStory.GameSelected.Id, (settings.IntegrationGraphicOptionsCountAbscissa - 1)); } else { GraphicsData = achievementsDatabase.GetCountByDay(SuccessStory.GameSelected.Id, (settings.IntegrationGraphicOptionsCountAbscissa - 1)); } string[] StatsGraphicsAchievementsLabels = GraphicsData.Labels; SeriesCollection StatsGraphicAchievementsSeries = new SeriesCollection(); StatsGraphicAchievementsSeries.Add(new LineSeries { Title = string.Empty, Values = GraphicsData.Series }); if (successStoryAchievementsGraphics == null) { successStoryAchievementsGraphics = new SuccessStoryAchievementsGraphics(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels, settings); if (!_IsCustom) { PART_SuccessStory_Graphic.Height = settings.IntegrationShowGraphicHeight; PART_SuccessStory_Graphic.Margin = new Thickness(0, 5, 0, 5); } PART_SuccessStory_Graphic.Children.Add(successStoryAchievementsGraphics); } successStoryAchievementsGraphics.SetScData(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels, settings); } } PART_SuccessStory_List.Visibility = Visibility.Collapsed; if (settings.IntegrationShowAchievements) { Show = true; if (_IsCustom && !_ShowAchievementsList) { Show = false; } #if DEBUG logger.Debug($"SuccessStory - PART_SuccessStory_List - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}"); #endif if (Show) { PART_SuccessStory_List.Visibility = Visibility.Visible; if (successStoryAchievementsList == null) { successStoryAchievementsList = new SuccessStoryAchievementsList(); if (!_IsCustom) { PART_SuccessStory_List.Height = settings.IntegrationShowAchievementsHeight; PART_SuccessStory_List.Margin = new Thickness(0, 5, 0, 5); } PART_SuccessStory_List.Children.Add(successStoryAchievementsList); } successStoryAchievementsList.SetScData(SelectedGameAchievements.Achievements, _IsCustom, settings.EnableRaretyIndicator); } } PART_SuccessStory_Compact_Locked.Visibility = Visibility.Collapsed; if (settings.IntegrationShowAchievementsCompactLocked) { Show = true; if (_IsCustom && !_ShowAchievementsCompactLocked) { Show = false; } #if DEBUG logger.Debug($"SuccessStory - PART_SuccessStory_Compact_Locked - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}"); #endif if (Show) { PART_SuccessStory_Compact_Locked.Visibility = Visibility.Visible; if (successStoryAchievementsCompact_Locked == null) { successStoryAchievementsCompact_Locked = new SuccessStoryAchievementsCompact(SelectedGameAchievements.Achievements, false, settings.EnableRaretyIndicator); if (!_IsCustom) { PART_SuccessStory_Compact_Locked.Margin = new Thickness(0, 5, 0, 5); PART_SuccessStory_Compact_Locked.Height = successStoryAchievementsCompact_Locked.Height; } PART_SuccessStory_Compact_Locked.Children.Add(successStoryAchievementsCompact_Locked); } successStoryAchievementsCompact_Locked.SetScData(SelectedGameAchievements.Achievements, false, settings.EnableRaretyIndicator); } } PART_SuccessStory_Compact_Unlocked.Visibility = Visibility.Collapsed; if (settings.IntegrationShowAchievementsCompactUnlocked) { Show = true; if (_IsCustom && !_ShowAchievementsCompactUnlocked) { Show = false; } #if DEBUG logger.Debug($"SuccessStory - PART_SuccessStory_Compact_Unlocked - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}"); #endif if (Show) { PART_SuccessStory_Compact_Unlocked.Visibility = Visibility.Visible; if (successStoryAchievementsCompact_Unlocked == null) { successStoryAchievementsCompact_Unlocked = new SuccessStoryAchievementsCompact(SelectedGameAchievements.Achievements, true, settings.EnableRaretyIndicator); if (!_IsCustom) { PART_SuccessStory_Compact_Unlocked.Margin = new Thickness(0, 5, 0, 5); PART_SuccessStory_Compact_Unlocked.Height = successStoryAchievementsCompact_Unlocked.Height; } PART_SuccessStory_Compact_Unlocked.Children.Add(successStoryAchievementsCompact_Unlocked); } successStoryAchievementsCompact_Unlocked.SetScData(SelectedGameAchievements.Achievements, true, settings.EnableRaretyIndicator); } } }
public SuccessView(SuccessStory plugin, SuccessStorySettings settings, IPlayniteAPI PlayniteApi, string PluginUserDataPath, bool isRetroAchievements = false, Game GameSelected = null) { this.plugin = plugin; this._PlayniteApi = PlayniteApi; _PlayniteApiDatabase = PlayniteApi.Database; _PlayniteApiPaths = PlayniteApi.Paths; this.settings = settings; this.PluginUserDataPath = PluginUserDataPath; InitializeComponent(); PART_DataLoad.Visibility = Visibility.Visible; PART_Data.Visibility = Visibility.Hidden; var TaskView = Task.Run(() => { AchievementsDb = new AchievementsDatabase(plugin, PlayniteApi, settings, PluginUserDataPath, isRetroAchievements); AchievementsDb.Initialize(false); GetListGame(); SetGraphicsAchievementsSources(); AchievementsGraphicsDataCount GraphicsData = null; if (settings.GraphicAllUnlockedByMonth) { GraphicsData = AchievementsDb.GetCountByMonth(null, 6); } else { GraphicsData = AchievementsDb.GetCountByDay(null, 5); } Application.Current.Dispatcher.BeginInvoke((Action) delegate { // Block hidden column. lvProgressionValue.IsEnabled = false; lvSourceName.IsEnabled = false; pbProgressionGlobalCount.Value = AchievementsDb.Progession().Unlocked; pbProgressionGlobalCount.Maximum = AchievementsDb.Progession().Total; labelProgressionGlobalCount.Content = AchievementsDb.Progession().Progression + "%"; pbProgressionLaunchedCount.Value = AchievementsDb.ProgessionLaunched().Unlocked; pbProgressionLaunchedCount.Maximum = AchievementsDb.ProgessionLaunched().Total; labelProgressionLaunchedCount.Content = AchievementsDb.ProgessionLaunched().Progression + "%"; GraphicTitle.Content = string.Empty; // lvGames options if (!settings.lvGamesIcon100Percent) { lvGameIcon100Percent.Width = 0; } if (!settings.lvGamesIcon) { lvGameIcon.Width = 0; } if (!settings.lvGamesName) { lvGameName.Width = 0; } if (!settings.lvGamesLastSession) { lvGameLastActivity.Width = 0; } if (!settings.lvGamesSource) { lvGamesSource.Width = 0; } if (!settings.lvGamesProgression) { lvGameProgression.Width = 0; } if (settings.GraphicAllUnlockedByMonth) { GraphicTitleALL.Content = resources.GetString("LOCSuccessStoryGraphicTitleALL"); } else { GraphicTitleALL.Content = resources.GetString("LOCSuccessStoryGraphicTitleALLDay"); } string[] StatsGraphicsAchievementsLabels = GraphicsData.Labels; SeriesCollection StatsGraphicAchievementsSeries = new SeriesCollection(); StatsGraphicAchievementsSeries.Add(new LineSeries { Title = string.Empty, Values = GraphicsData.Series }); SuccessStory_Achievements_Graphics.Children.Clear(); settings.IgnoreSettings = true; SuccessStory_Achievements_Graphics.Children.Add(new SuccessStoryAchievementsGraphics(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels, settings)); SuccessStory_Achievements_Graphics.UpdateLayout(); // Set game selected if (GameSelected != null) { for (int i = 0; i < ListviewGames.Items.Count; i++) { if (((ListViewGames)ListviewGames.Items[i]).Name == GameSelected.Name) { ListviewGames.SelectedIndex = i; } } } ListviewGames.ScrollIntoView(ListviewGames.SelectedItem); string icon = string.Empty; if (settings.EnableRetroAchievementsView && settings.EnableRetroAchievements) { if (isRetroAchievements) { PART_GraphicBySource.Visibility = Visibility.Collapsed; Grid.SetColumn(PART_GraphicAllUnlocked, 0); Grid.SetColumnSpan(PART_GraphicAllUnlocked, 3); if (settings.EnableRetroAchievements) { icon = TransformIcon.Get("RetroAchievements") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "RetroAchievements", SourceNameShort = "RetroAchievements", IsCheck = false }); } } else { if (settings.EnableLocal) { icon = TransformIcon.Get("Playnite") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Playnite", SourceNameShort = "Playnite", IsCheck = false }); } if (settings.EnableSteam) { icon = TransformIcon.Get("Steam") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Steam", SourceNameShort = "Steam", IsCheck = false }); } if (settings.EnableGog) { icon = TransformIcon.Get("GOG") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "GOG", SourceNameShort = "GOG", IsCheck = false }); } if (settings.EnableOrigin) { icon = TransformIcon.Get("Origin") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Origin", SourceNameShort = "Origin", IsCheck = false }); } if (settings.EnableXbox) { icon = TransformIcon.Get("Xbox") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Xbox", SourceNameShort = "Xbox", IsCheck = false }); } } } else { if (settings.EnableLocal) { icon = TransformIcon.Get("Playnite") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Playnite", SourceNameShort = "Playnite", IsCheck = false }); } if (settings.EnableSteam) { icon = TransformIcon.Get("Steam") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Steam", SourceNameShort = "Steam", IsCheck = false }); } if (settings.EnableGog) { icon = TransformIcon.Get("GOG") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "GOG", SourceNameShort = "GOG", IsCheck = false }); } if (settings.EnableOrigin) { icon = TransformIcon.Get("Origin") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Origin", SourceNameShort = "Origin", IsCheck = false }); } if (settings.EnableXbox) { icon = TransformIcon.Get("Xbox") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Xbox", SourceNameShort = "Xbox", IsCheck = false }); } if (settings.EnableRetroAchievements) { icon = TransformIcon.Get("RetroAchievements") + " "; FilterSourceItems.Add(new ListSource { SourceName = ((icon.Length == 2) ? icon : string.Empty) + "RetroAchievements", SourceNameShort = "RetroAchievements", IsCheck = false }); } } FilterSource.ItemsSource = FilterSourceItems; // Set Binding data DataContext = this; PART_DataLoad.Visibility = Visibility.Hidden; PART_Data.Visibility = Visibility.Visible; }); }); }