private void PART_BtSelectGame_Click(object sender, RoutedEventArgs e)
        {
            int      index        = PART_ListGame.SelectedIndex;
            ListGame SelectedItem = (ListGame)PART_ListGame.SelectedItem;

            PART_ListGame.ItemsSource = null;
            listGames.RemoveAt(index);
            PART_ListGame.ItemsSource = listGames;


            string Icon = string.Empty;

            if (!SelectedItem.Icon.IsNullOrEmpty())
            {
                Icon = PluginDatabase.PlayniteApi.Database.GetFullFilePath(SelectedItem.Icon);
            }

            listGameScreenshots.Add(new ListGameScreenshot
            {
                Id   = SelectedItem.Id,
                Icon = Icon,
                Name = SelectedItem.Name,
                ScreenshotsFolders = new List <FolderSettings>(),
                UsedFilePattern    = false,
                FilePattern        = string.Empty,
                SourceName         = SelectedItem.SourceName,
                SourceIcon         = TransformIcon.Get(SelectedItem.SourceName)
            });

            listGameScreenshots.Sort((x, y) => x.Name.CompareTo(y.Name));
            PART_ListGameScreenshot.ItemsSource = null;
            PART_ListGameScreenshot.ItemsSource = listGameScreenshots;

            TextboxSearch_TextChanged(null, null);
        }
Ejemplo n.º 2
0
        /// <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 ");
            }
        }
Ejemplo n.º 3
0
        public override void OnApplicationStarted()
        {
            // Add code to be executed when Playnite is initialized.

            if (settings.EnableIntegrationButtonHeader)
            {
                Button btHeader = new StatisticsButtonHeader(TransformIcon.Get("Statistics"));
                btHeader.Click += OnBtHeaderClick;
                ui.AddButtonInWindowsHeader(btHeader);
            }
        }
Ejemplo n.º 4
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string Result = "";

            if (TransformIcon.Get((string)value).Length == 1 && CustomerToolTipForTime._ShowIcon)
            {
                Result = TransformIcon.Get((string)value);
            }

            return(Result);
        }
Ejemplo n.º 5
0
        public override void OnApplicationStarted()
        {
            // Add code to be executed when Playnite is initialized.

            if (settings.EnableIntegrationButtonHeader)
            {
                logger.Info("SuccessStory - Add Header button");
                Button btHeader = new SuccessStoryButtonHeader(TransformIcon.Get("SuccessStory"));
                btHeader.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold);
                btHeader.Click += OnBtHeaderClick;
                ui.AddButtonInWindowsHeader(btHeader);
            }
        }
Ejemplo n.º 6
0
 public void AddBtHeader()
 {
     if (_PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop)
     {
         if (PluginDatabase.PluginSettings.EnableIntegrationButtonHeader)
         {
             logger.Info("SuccessStory - Add Header button");
             Button btHeader = new SuccessStoryButtonHeader(TransformIcon.Get("SuccessStory"));
             btHeader.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold);
             btHeader.Click += OnBtHeaderClick;
             ui.AddButtonInWindowsHeader(btHeader);
         }
     }
 }
        // Add RetroArch game automaticly
        private void PART_BtAddURetroArch_Click(object sender, RoutedEventArgs e)
        {
            TextboxSearch.Text = string.Empty;

            var tmpList = Serialization.GetClone(listGames).Where(x => PlayniteTools.GameUseRetroArch(PluginDatabase.PlayniteApi.Database.Games.Get(x.Id))).ToList();

            foreach (var game in tmpList)
            {
                int index = listGames.FindIndex(x => x.Id == game.Id);
                listGames.RemoveAt(index);

                string Icon = string.Empty;
                if (!game.Icon.IsNullOrEmpty())
                {
                    Icon = PluginDatabase.PlayniteApi.Database.GetFullFilePath(game.Icon);
                }

                List <FolderSettings> ScreenshotsFolders = new List <FolderSettings>();
                ScreenshotsFolders.Add(new FolderSettings
                {
                    ScreenshotsFolder = "{RetroArchScreenshotsDir}",
                    UsedFilePattern   = true,
                    FilePattern       = "{ImageNameNoExt}-{digit}-{digit}",
                });

                listGameScreenshots.Add(new ListGameScreenshot
                {
                    Id   = game.Id,
                    Icon = Icon,
                    Name = game.Name,
                    ScreenshotsFolders = ScreenshotsFolders,
                    SourceName         = game.SourceName,
                    SourceIcon         = TransformIcon.Get(game.SourceName)
                });
            }

            PART_ListGame.ItemsSource = null;
            PART_ListGame.ItemsSource = listGames;

            listGameScreenshots.Sort((x, y) => x.Name.CompareTo(y.Name));
            PART_ListGameScreenshot.ItemsSource = null;
            PART_ListGameScreenshot.ItemsSource = listGameScreenshots;

            TextboxSearch_TextChanged(null, null);
        }
        // Add Ubisoft Connect game automaticly
        private void PART_BtAddUplay_Click(object sender, RoutedEventArgs e)
        {
            TextboxSearch.Text = string.Empty;

            var tmpList = Serialization.GetClone(listGames).Where(x => x.SourceName.ToLower() == "ubisoft connect" || x.SourceName.ToLower() == "uplay").ToList();

            foreach (var game in tmpList)
            {
                int index = listGames.FindIndex(x => x.Id == game.Id);
                listGames.RemoveAt(index);

                string Icon = string.Empty;
                if (!game.Icon.IsNullOrEmpty())
                {
                    Icon = PluginDatabase.PlayniteApi.Database.GetFullFilePath(game.Icon);
                }

                List <FolderSettings> ScreenshotsFolders = new List <FolderSettings>();
                ScreenshotsFolders.Add(new FolderSettings
                {
                    ScreenshotsFolder = "{UbisoftScreenshotsDir}\\" + game.Name
                });

                listGameScreenshots.Add(new ListGameScreenshot
                {
                    Id   = game.Id,
                    Icon = Icon,
                    Name = game.Name,
                    ScreenshotsFolders = ScreenshotsFolders,
                    SourceName         = game.SourceName,
                    SourceIcon         = TransformIcon.Get(game.SourceName)
                });
            }

            PART_ListGame.ItemsSource = null;
            PART_ListGame.ItemsSource = listGames;

            listGameScreenshots.Sort((x, y) => x.Name.CompareTo(y.Name));
            PART_ListGameScreenshot.ItemsSource = null;
            PART_ListGameScreenshot.ItemsSource = listGameScreenshots;

            TextboxSearch_TextChanged(null, null);
        }
Ejemplo n.º 9
0
        public override void OnApplicationStarted()
        {
            // Add code to be executed when Playnite is initialized.

            if (settings.EnableIntegrationButton)
            {
                foreach (Button bt in Tools.FindVisualChildren <Button>(Application.Current.MainWindow))
                {
                    if (bt.Name == "PART_ButtonSteamFriends")
                    {
                        logger.Debug("Statistics - PART_ButtonSteamFriends find");

                        Button sBt = new StatisticsButton(TransformIcon.Get("statistics"));
                        sBt.Click += sBt_ClickEvent;
                        sBt.Width  = bt.ActualWidth;
                        DockPanel.SetDock(sBt, Dock.Right);

                        DockPanel ControlParent = ((DockPanel)bt.Parent);
                        for (int i = 0; i < ControlParent.Children.Count; i++)
                        {
                            if (((FrameworkElement)ControlParent.Children[i]).Name == "PART_ButtonSteamFriends")
                            {
                                logger.Debug("Statistics - sBt add");
                                ControlParent.Children.Insert((i - 1), sBt);
                                i = 200;
                            }
                        }

                        break;
                    }
                    else
                    {
                        logger.Debug("Statistics - PART_ButtonSteamFriends not find");
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        public void GetListGame()
        {
            string pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            try
            {
                if (ListGames.Count == 0)
                {
                    var dataGameAchievements = AchievementsDb.gameAchievements.Where(x => x.Value.HaveAchivements);
                    foreach (var item in dataGameAchievements)
                    {
                        Game   game       = _PlayniteApiDatabase.Games.Get(item.Key);
                        string SourceName = PlayniteTools.GetSourceName(game, _PlayniteApi);

                        if (AchievementsDatabase.VerifToAddOrShow(plugin, _PlayniteApi, SourceName, settings, PluginUserDataPath))
                        {
                            string   GameId           = game.Id.ToString();
                            string   GameName         = game.Name;
                            string   GameIcon         = string.Empty;
                            string   Icon100          = string.Empty;
                            DateTime?GameLastActivity = null;

                            GameAchievements GameAchievements = AchievementsDb.Get(game.Id);

                            if (game.LastActivity != null)
                            {
                                GameLastActivity = ((DateTime)game.LastActivity).ToLocalTime();
                            }

                            if (!game.Icon.IsNullOrEmpty())
                            {
                                GameIcon = _PlayniteApiDatabase.GetFullFilePath(game.Icon);
                            }

                            if (GameAchievements.Is100Percent)
                            {
                                Icon100 = Path.Combine(pluginFolder, "Resources\\badge.png");
                            }

                            ListGames.Add(new ListViewGames()
                            {
                                Icon100Percent   = Icon100,
                                Id               = GameId,
                                Name             = GameName,
                                Icon             = GameIcon,
                                LastActivity     = GameLastActivity,
                                SourceName       = SourceName,
                                SourceIcon       = TransformIcon.Get(SourceName),
                                ProgressionValue = GameAchievements.Progression,
                                Total            = GameAchievements.Total,
                                TotalPercent     = GameAchievements.Progression + "%",
                                Unlocked         = GameAchievements.Unlocked
                            });
                        }
                    }
                }

                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                {
                    ListviewGames.ItemsSource = ListGames;
                    Sorting();
                });
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SuccessStory", "Errorn on GetListGames()");
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Set list sources available in database.
        /// </summary>
        /// <param name="PlayniteApiDatabase"></param>
        internal void SetListSource(IGameDatabaseAPI PlayniteApiDatabase)
        {
            s1.Visibility  = Visibility.Hidden;
            s2.Visibility  = Visibility.Hidden;
            s3.Visibility  = Visibility.Hidden;
            s4.Visibility  = Visibility.Hidden;
            s5.Visibility  = Visibility.Hidden;
            s6.Visibility  = Visibility.Hidden;
            s7.Visibility  = Visibility.Hidden;
            s8.Visibility  = Visibility.Hidden;
            s9.Visibility  = Visibility.Hidden;
            s10.Visibility = Visibility.Hidden;
            s11.Visibility = Visibility.Hidden;
            s12.Visibility = Visibility.Hidden;
            s13.Visibility = Visibility.Hidden;


            int iCount = 1;

            // Playnite
            string SourceName = TransformIcon.Get("Playnite");

            if (SourceName.Length != 1)
            {
                SourceName = "Playnite";
            }
            else
            {
                SourceName = SourceName + " " + "Playnite";
            }

            if (StatisticsDatabase.HaveGame(Guid.Parse("00000000-0000-0000-0000-000000000000")))
            {
                s1.Tag        = "00000000-0000-0000-0000-000000000000";
                s1.Content    = SourceName;
                s1.Visibility = Visibility.Visible;
                iCount       += 1;
            }


            foreach (var item in PlayniteApiDatabase.Sources)
            {
                SourceName = TransformIcon.Get(item.Name);

                if (SourceName.Length != 1)
                {
                    SourceName = item.Name;
                }
                else
                {
                    SourceName = SourceName + " " + item.Name;
                }

                if (StatisticsDatabase.HaveGame(item.Id))
                {
                    switch (iCount)
                    {
                    case 1:
                        s1.Tag        = item.Id.ToString();
                        s1.Content    = SourceName;
                        s1.Visibility = Visibility.Visible;
                        break;

                    case 2:
                        s2.Tag        = item.Id.ToString();
                        s2.Content    = SourceName;
                        s2.Visibility = Visibility.Visible;
                        break;

                    case 3:
                        s3.Tag        = item.Id.ToString();
                        s3.Content    = SourceName;
                        s3.Visibility = Visibility.Visible;
                        break;

                    case 4:
                        s4.Tag        = item.Id.ToString();
                        s4.Content    = SourceName;
                        s4.Visibility = Visibility.Visible;
                        break;

                    case 5:
                        s5.Tag        = item.Id.ToString();
                        s5.Content    = SourceName;
                        s5.Visibility = Visibility.Visible;
                        break;

                    case 6:
                        s6.Tag        = item.Id.ToString();
                        s6.Content    = SourceName;
                        s6.Visibility = Visibility.Visible;
                        break;

                    case 7:
                        s7.Tag        = item.Id.ToString();
                        s7.Content    = SourceName;
                        s7.Visibility = Visibility.Visible;
                        break;

                    case 8:
                        s8.Tag        = item.Id.ToString();
                        s8.Content    = SourceName;
                        s8.Visibility = Visibility.Visible;
                        break;

                    case 9:
                        s9.Tag        = item.Id.ToString();
                        s9.Content    = SourceName;
                        s9.Visibility = Visibility.Visible;
                        break;

                    case 10:
                        s10.Tag        = item.Id.ToString();
                        s10.Content    = SourceName;
                        s10.Visibility = Visibility.Visible;
                        break;

                    case 11:
                        s11.Tag        = item.Id.ToString();
                        s11.Content    = SourceName;
                        s11.Visibility = Visibility.Visible;
                        break;

                    case 12:
                        s12.Tag        = item.Id.ToString();
                        s12.Content    = SourceName;
                        s12.Visibility = Visibility.Visible;
                        break;

                    case 13:
                        s13.Tag        = item.Id.ToString();
                        s13.Content    = SourceName;
                        s13.Visibility = Visibility.Visible;
                        break;
                    }

                    iCount += 1;
                }
            }

            s0.IsChecked = true;
        }
Ejemplo n.º 12
0
        public AchievementsGraphicsDataCountSources GetCountBySources()
        {
            List <string> tempSourcesLabels = new List <string>();

            if (PluginSettings.EnableRetroAchievementsView && PluginSettings.EnableRetroAchievements)
            {
                if (_isRetroachievements)
                {
                    if (PluginSettings.EnableRetroAchievements)
                    {
                        tempSourcesLabels.Add("RetroAchievements");
                    }
                }
                else
                {
                    if (PluginSettings.EnableGog)
                    {
                        tempSourcesLabels.Add("GOG");
                    }
                    if (PluginSettings.EnableSteam)
                    {
                        tempSourcesLabels.Add("Steam");
                    }
                    if (PluginSettings.EnableOrigin)
                    {
                        tempSourcesLabels.Add("Origin");
                    }
                    if (PluginSettings.EnableXbox)
                    {
                        tempSourcesLabels.Add("Xbox");
                    }
                    if (PluginSettings.EnableLocal)
                    {
                        tempSourcesLabels.Add("Playnite");
                        tempSourcesLabels.Add("Hacked");
                    }
                    if (PluginSettings.EnableRpcs3Achievements)
                    {
                        tempSourcesLabels.Add("RPCS3");
                    }
                }
            }
            else
            {
                if (PluginSettings.EnableGog)
                {
                    tempSourcesLabels.Add("GOG");
                }
                if (PluginSettings.EnableSteam)
                {
                    tempSourcesLabels.Add("Steam");
                }
                if (PluginSettings.EnableOrigin)
                {
                    tempSourcesLabels.Add("Origin");
                }
                if (PluginSettings.EnableXbox)
                {
                    tempSourcesLabels.Add("Xbox");
                }
                if (PluginSettings.EnableRetroAchievements)
                {
                    tempSourcesLabels.Add("RetroAchievements");
                }
                if (PluginSettings.EnableRpcs3Achievements)
                {
                    tempSourcesLabels.Add("RPCS3");
                }
                if (PluginSettings.EnableLocal)
                {
                    tempSourcesLabels.Add("Playnite");
                    tempSourcesLabels.Add("Hacked");
                }
            }

            tempSourcesLabels.Sort((x, y) => x.CompareTo(y));

            string[] GraphicsAchievementsLabels = new string[tempSourcesLabels.Count];
            List <AchievementsGraphicsDataSources> tempDataUnlocked = new List <AchievementsGraphicsDataSources>();
            List <AchievementsGraphicsDataSources> tempDataLocked   = new List <AchievementsGraphicsDataSources>();
            List <AchievementsGraphicsDataSources> tempDataTotal    = new List <AchievementsGraphicsDataSources>();

            for (int i = 0; i < tempSourcesLabels.Count; i++)
            {
                GraphicsAchievementsLabels[i] = TransformIcon.Get(tempSourcesLabels[i]);
                tempDataLocked.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
                tempDataUnlocked.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
                tempDataTotal.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
            }


            foreach (var item in Database.Items)
            {
                if (!item.Value.HaveAchivements || item.Value.IsDeleted)
                {
                    continue;
                }

                try
                {
                    string SourceName = PlayniteTools.GetSourceName(_PlayniteApi, item.Key);

                    foreach (Achievements achievements in item.Value.Items)
                    {
                        for (int i = 0; i < tempDataUnlocked.Count; i++)
                        {
                            if (tempDataUnlocked[i].source == SourceName)
                            {
                                tempDataTotal[i].value += 1;
                                if (achievements.DateUnlocked != default(DateTime))
                                {
                                    tempDataUnlocked[i].value += 1;
                                }
                                if (achievements.DateUnlocked == default(DateTime))
                                {
                                    tempDataLocked[i].value += 1;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "SuccessStory", $"Error on GetCountBySources() for {item.Key}");
                }
            }

            ChartValues <CustomerForSingle> SourceAchievementsSeriesUnlocked = new ChartValues <CustomerForSingle>();
            ChartValues <CustomerForSingle> SourceAchievementsSeriesLocked   = new ChartValues <CustomerForSingle>();
            ChartValues <CustomerForSingle> SourceAchievementsSeriesTotal    = new ChartValues <CustomerForSingle>();

            for (int i = 0; i < tempDataUnlocked.Count; i++)
            {
                SourceAchievementsSeriesUnlocked.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataUnlocked[i].source),
                    Values = tempDataUnlocked[i].value
                });
                SourceAchievementsSeriesLocked.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataLocked[i].source),
                    Values = tempDataLocked[i].value
                });
                SourceAchievementsSeriesTotal.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataTotal[i].source),
                    Values = tempDataTotal[i].value
                });
            }


            return(new AchievementsGraphicsDataCountSources
            {
                Labels = GraphicsAchievementsLabels,
                SeriesLocked = SourceAchievementsSeriesLocked,
                SeriesUnlocked = SourceAchievementsSeriesUnlocked,
                SeriesTotal = SourceAchievementsSeriesTotal
            });
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Set list sources available in database.
        /// </summary>
        /// <param name="PlayniteApiDatabase"></param>
        internal void SetListSource(IGameDatabaseAPI PlayniteApiDatabase)
        {
            s1.Visibility  = Visibility.Hidden;
            s2.Visibility  = Visibility.Hidden;
            s3.Visibility  = Visibility.Hidden;
            s4.Visibility  = Visibility.Hidden;
            s5.Visibility  = Visibility.Hidden;
            s6.Visibility  = Visibility.Hidden;
            s7.Visibility  = Visibility.Hidden;
            s8.Visibility  = Visibility.Hidden;
            s9.Visibility  = Visibility.Hidden;
            s10.Visibility = Visibility.Hidden;
            s11.Visibility = Visibility.Hidden;
            s12.Visibility = Visibility.Hidden;
            s13.Visibility = Visibility.Hidden;


            int iCount = 1;

            // Playnite
            string SourceName = TransformIcon.Get("Playnite");

            if (SourceName.Length != 1)
            {
                SourceName = "Playnite";
            }
            else
            {
                SourceName = SourceName + " " + "Playnite";
            }

            if (StatisticsDatabase.HaveGame(Guid.Parse("00000000-0000-0000-0000-000000000000")))
            {
                s1.Tag        = "00000000-0000-0000-0000-000000000000";
                s1.Content    = SourceName;
                s1.Visibility = Visibility.Visible;
                iCount       += 1;
            }


            #region Set list sources
            // Set emulators sources (cbEmulators)
            List <dataEmulators> ListEmulators = new List <dataEmulators>();
            foreach (var item in PlayniteApiDatabase.Emulators)
            {
                ListEmulators.Add(new dataEmulators {
                    Id = item.Id, Name = item.Name
                });
            }
            cbEmulators.ItemsSource = ListEmulators;
            if (ListEmulators.Count == 0)
            {
                spEmulators.Visibility = Visibility.Hidden;
            }
            // Get link source for emulator
            else
            {
                foreach (var game in PlayniteApiDatabase.Games)
                {
                    if (game.PlayAction != null && game.PlayAction.EmulatorId != null)
                    {
                        for (int i = 0; i < ListEmulators.Count; i++)
                        {
                            if (ListEmulators[i].Id == game.PlayAction.EmulatorId)
                            {
                                ListEmulators[i].SourceId = game.SourceId;
                                if (game.SourceId == Guid.Parse("00000000-0000-0000-0000-000000000000"))
                                {
                                    ListEmulators[i].SourceName = "";
                                }
                                else
                                {
                                    ListEmulators[i].SourceName = game.Source.Name;
                                }
                                i = ListEmulators.Count;
                            }
                        }
                    }
                }
            }

            // Set pc sources
            foreach (var item in PlayniteApiDatabase.Sources)
            {
                bool IsEmulators = false;
                for (int i = 0; i < ListEmulators.Count; i++)
                {
                    if (ListEmulators[i].SourceId == item.Id)
                    {
                        IsEmulators = true;
                    }
                }

                if (!IsEmulators)
                {
                    SourceName = TransformIcon.Get(item.Name);

                    if (SourceName.Length != 1)
                    {
                        SourceName = item.Name;
                    }
                    else
                    {
                        SourceName = SourceName + " " + item.Name;
                    }

                    if (StatisticsDatabase.HaveGame(item.Id))
                    {
                        switch (iCount)
                        {
                        case 1:
                            s1.Tag        = item.Id.ToString();
                            s1.Content    = SourceName;
                            s1.Visibility = Visibility.Visible;
                            break;

                        case 2:
                            s2.Tag        = item.Id.ToString();
                            s2.Content    = SourceName;
                            s2.Visibility = Visibility.Visible;
                            break;

                        case 3:
                            s3.Tag        = item.Id.ToString();
                            s3.Content    = SourceName;
                            s3.Visibility = Visibility.Visible;
                            break;

                        case 4:
                            s4.Tag        = item.Id.ToString();
                            s4.Content    = SourceName;
                            s4.Visibility = Visibility.Visible;
                            break;

                        case 5:
                            s5.Tag        = item.Id.ToString();
                            s5.Content    = SourceName;
                            s5.Visibility = Visibility.Visible;
                            break;

                        case 6:
                            s6.Tag        = item.Id.ToString();
                            s6.Content    = SourceName;
                            s6.Visibility = Visibility.Visible;
                            break;

                        case 7:
                            s7.Tag        = item.Id.ToString();
                            s7.Content    = SourceName;
                            s7.Visibility = Visibility.Visible;
                            break;

                        case 8:
                            s8.Tag        = item.Id.ToString();
                            s8.Content    = SourceName;
                            s8.Visibility = Visibility.Visible;
                            break;

                        case 9:
                            s9.Tag        = item.Id.ToString();
                            s9.Content    = SourceName;
                            s9.Visibility = Visibility.Visible;
                            break;

                        case 10:
                            s10.Tag        = item.Id.ToString();
                            s10.Content    = SourceName;
                            s10.Visibility = Visibility.Visible;
                            break;

                        case 11:
                            s11.Tag        = item.Id.ToString();
                            s11.Content    = SourceName;
                            s11.Visibility = Visibility.Visible;
                            break;

                        case 12:
                            s12.Tag        = item.Id.ToString();
                            s12.Content    = SourceName;
                            s12.Visibility = Visibility.Visible;
                            break;

                        case 13:
                            s13.Tag        = item.Id.ToString();
                            s13.Content    = SourceName;
                            s13.Visibility = Visibility.Visible;
                            break;
                        }

                        iCount += 1;
                    }
                }
            }

            s0.IsChecked = true;
            #endregion
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        /// <param name="SearchGameName"></param>
        public void GetListGame(string SearchGameName = "", List <string> SearchSourceName = null)
        {
            logger.Debug("SearchGameName: " + SearchGameName);
            logger.Debug("SearchSourceName: " + JsonConvert.SerializeObject(SearchSourceName));

            List <ListGames> ListGames = new List <ListGames>();

            foreach (var item in PlayniteApiDatabase.Games)
            {
                string GameSourceName = "";
                if (item.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                {
                    GameSourceName = item.Source.Name;
                }
                else
                {
                    GameSourceName = "Playnite";
                }


                bool isFind = false;

                if (SearchSourceName != null)
                {
                    for (int i = 0; i < SearchSourceName.Count; i++)
                    {
                        if (GameSourceName.ToLower().Contains(SearchSourceName[i].ToLower()))
                        {
                            isFind = true;
                        }
                    }
                }

                if (SearchGameName != "")
                {
                    if (item.Name.ToLower().Contains(SearchGameName.ToLower()))
                    {
                        isFind = true;
                    }
                }

                if (SearchGameName != "" && SearchSourceName != null)
                {
                    isFind = false;

                    for (int i = 0; i < SearchSourceName.Count; i++)
                    {
                        if ((GameSourceName.ToLower().Contains(SearchSourceName[i].ToLower())) && (item.Name.ToLower().Contains(SearchGameName.ToLower())))
                        {
                            isFind = true;
                        }
                    }
                }

                if (SearchGameName == "" && SearchSourceName == null)
                {
                    isFind = true;
                }


                if (isFind && AchievementsDatabase.HaveAchievements(item.Id))
                {
                    if (AchievementsDatabase.VerifToAddOrShow(GameSourceName, settings))
                    {
                        string   GameId   = item.Id.ToString();
                        string   GameName = item.Name;
                        string   GameIcon;
                        DateTime?GameLastActivity = null;

                        string SourceName = "";
                        if (item.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                        {
                            SourceName = item.Source.Name;
                        }
                        else
                        {
                            SourceName = "Playnite";
                        }

                        GameAchievements GameAchievements = AchievementsDatabase.Get(item.Id);

                        if (item.LastActivity != null)
                        {
                            GameLastActivity = ((DateTime)item.LastActivity).ToLocalTime();
                        }

                        BitmapImage iconImage = new BitmapImage();
                        if (String.IsNullOrEmpty(item.Icon) == false)
                        {
                            iconImage.BeginInit();
                            GameIcon            = PlayniteApiDatabase.GetFullFilePath(item.Icon);
                            iconImage.UriSource = new Uri(GameIcon, UriKind.RelativeOrAbsolute);
                            iconImage.EndInit();
                        }

                        ListGames.Add(new ListGames()
                        {
                            Id               = GameId,
                            Name             = GameName,
                            Icon             = iconImage,
                            LastActivity     = GameLastActivity,
                            SourceName       = SourceName,
                            SourceIcon       = TransformIcon.Get(SourceName),
                            ProgressionValue = GameAchievements.Progression,
                            Total            = GameAchievements.Total,
                            TotalPercent     = GameAchievements.Progression + "%",
                            Unlocked         = GameAchievements.Unlocked
                        });

                        iconImage = null;
                    }
                }
            }

            ListviewGames.ItemsSource = ListGames;

            // Sorting
            try
            {
                var columnBinding = _lastHeaderClicked.Column.DisplayMemberBinding as Binding;
                var sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;

                // Specific sort with another column
                if (_lastHeaderClicked.Name == "lvSourceIcon")
                {
                    columnBinding = lvSourceName.Column.DisplayMemberBinding as Binding;
                    sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;
                }
                if (_lastHeaderClicked.Name == "lvProgression")
                {
                    columnBinding = lvProgressionValue.Column.DisplayMemberBinding as Binding;
                    sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;
                }
                Sort(sortBy, _lastDirection);
            }
            // If first view
            catch
            {
                CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(ListviewGames.ItemsSource);

                logger.Debug("sort - " + settings.NameSorting + " - " + _lastDirection.ToString());

                switch (settings.NameSorting)
                {
                case ("Name"):
                    _lastHeaderClicked = lvName;
                    if (settings.IsAsc)
                    {
                        _lastHeaderClicked.Content += " ▲";
                    }
                    else
                    {
                        _lastHeaderClicked.Content += " ▼";
                    }
                    break;

                case ("LastActivity"):
                    _lastHeaderClicked = lvLastActivity;
                    if (settings.IsAsc)
                    {
                        _lastHeaderClicked.Content += " ▲";
                    }
                    else
                    {
                        _lastHeaderClicked.Content += " ▼";
                    }
                    break;

                case ("SourceName"):
                    _lastHeaderClicked = lvSourceIcon;
                    if (settings.IsAsc)
                    {
                        lvSourceIcon.Content += " ▲";
                    }
                    else
                    {
                        lvSourceIcon.Content += " ▼";
                    }
                    break;

                case ("ProgressionValue"):
                    _lastHeaderClicked = lvProgression;
                    if (settings.IsAsc)
                    {
                        lvProgression.Content += " ▲";
                    }
                    else
                    {
                        lvProgression.Content += " ▼";
                    }
                    break;
                }


                if (settings.IsAsc)
                {
                    _lastDirection = ListSortDirection.Ascending;
                }
                else
                {
                    _lastDirection = ListSortDirection.Descending;
                }


                view.SortDescriptions.Add(new SortDescription(settings.NameSorting, _lastDirection));
            }
        }
        public SuccessView(SuccessStory plugin, IPlayniteAPI PlayniteApi, string PluginUserDataPath, bool isRetroAchievements = false, Game GameSelected = null)
        {
            _plugin              = plugin;
            _PlayniteApi         = PlayniteApi;
            _PlayniteApiDatabase = PlayniteApi.Database;
            _PlayniteApiPaths    = PlayniteApi.Paths;
            _PluginUserDataPath  = PluginUserDataPath;


            InitializeComponent();


            PART_DataLoad.Visibility = Visibility.Visible;
            PART_Data.Visibility     = Visibility.Hidden;

            var TaskView = Task.Run(() =>
            {
                GetListGame();
                SetGraphicsAchievementsSources();

                this.Dispatcher.BeginInvoke((Action) delegate
                {
                    // Block hidden column.
                    lvProgressionValue.IsEnabled = false;
                    lvSourceName.IsEnabled       = false;


                    pbProgressionGlobalCount.Value      = PluginDatabase.Progession().Unlocked;
                    pbProgressionGlobalCount.Maximum    = PluginDatabase.Progession().Total;
                    labelProgressionGlobalCount.Content = PluginDatabase.Progession().Progression + "%";

                    pbProgressionLaunchedCount.Value      = PluginDatabase.ProgessionLaunched().Unlocked;
                    pbProgressionLaunchedCount.Maximum    = PluginDatabase.ProgessionLaunched().Total;
                    labelProgressionLaunchedCount.Content = PluginDatabase.ProgessionLaunched().Progression + "%";


                    GraphicTitle.Content = string.Empty;


                    // lvGames options
                    if (!PluginDatabase.PluginSettings.lvGamesIcon100Percent)
                    {
                        lvGameIcon100Percent.Width = 0;
                    }
                    if (!PluginDatabase.PluginSettings.lvGamesIcon)
                    {
                        lvGameIcon.Width = 0;
                    }
                    if (!PluginDatabase.PluginSettings.lvGamesName)
                    {
                        lvGameName.Width = 0;
                    }
                    if (!PluginDatabase.PluginSettings.lvGamesLastSession)
                    {
                        lvGameLastActivity.Width = 0;
                    }
                    if (!PluginDatabase.PluginSettings.lvGamesSource)
                    {
                        lvGamesSource.Width = 0;
                    }
                    if (!PluginDatabase.PluginSettings.lvGamesProgression)
                    {
                        lvGameProgression.Width = 0;
                    }

                    int limit = 5;
                    GraphicTitleALL.Content = resources.GetString("LOCSuccessStoryGraphicTitleALL");

                    SuccessStory_Achievements_Graphics.Children.Clear();
                    PluginDatabase.PluginSettings.IgnoreSettings = true;
                    SuccessStoryAchievementsGraphics successStoryAchievementsGraphics = new SuccessStoryAchievementsGraphics();
                    successStoryAchievementsGraphics.SetScData(null, limit, true);
                    SuccessStory_Achievements_Graphics.Children.Add(successStoryAchievementsGraphics);
                    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 (PluginDatabase.PluginSettings.EnableRetroAchievementsView && PluginDatabase.PluginSettings.EnableRetroAchievements)
                    {
                        if (isRetroAchievements)
                        {
                            PART_GraphicBySource.Visibility = Visibility.Collapsed;
                            Grid.SetColumn(PART_GraphicAllUnlocked, 0);
                            Grid.SetColumnSpan(PART_GraphicAllUnlocked, 3);

                            if (PluginDatabase.PluginSettings.EnableRetroAchievements)
                            {
                                icon = TransformIcon.Get("RetroAchievements") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "RetroAchievements", SourceNameShort = "RetroAchievements", IsCheck = false
                                });
                            }
                        }
                        else
                        {
                            if (PluginDatabase.PluginSettings.EnableLocal)
                            {
                                icon = TransformIcon.Get("Playnite") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Playnite", SourceNameShort = "Playnite", IsCheck = false
                                });

                                icon = TransformIcon.Get("Hacked") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Hacked", SourceNameShort = "Hacked", IsCheck = false
                                });
                            }
                            if (PluginDatabase.PluginSettings.EnableSteam)
                            {
                                icon = TransformIcon.Get("Steam") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Steam", SourceNameShort = "Steam", IsCheck = false
                                });
                            }
                            if (PluginDatabase.PluginSettings.EnableGog)
                            {
                                icon = TransformIcon.Get("GOG") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "GOG", SourceNameShort = "GOG", IsCheck = false
                                });
                            }
                            if (PluginDatabase.PluginSettings.EnableOrigin)
                            {
                                icon = TransformIcon.Get("Origin") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Origin", SourceNameShort = "Origin", IsCheck = false
                                });
                            }
                            if (PluginDatabase.PluginSettings.EnableXbox)
                            {
                                icon = TransformIcon.Get("Xbox") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Xbox", SourceNameShort = "Xbox", IsCheck = false
                                });
                            }
                            if (PluginDatabase.PluginSettings.EnableRpcs3Achievements)
                            {
                                icon = TransformIcon.Get("Rpcs3") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Rpcs3", SourceNameShort = "Rpcs3", IsCheck = false
                                });
                            }
                            if (PluginDatabase.PluginSettings.EnableManual)
                            {
                                icon = TransformIcon.Get("Manual") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Manual", SourceNameShort = "Manual", IsCheck = false
                                });
                            }
                        }
                    }
                    else
                    {
                        if (PluginDatabase.PluginSettings.EnableLocal)
                        {
                            icon = TransformIcon.Get("Playnite") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Playnite", SourceNameShort = "Playnite", IsCheck = false
                            });

                            icon = TransformIcon.Get("Hacked") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Hacked", SourceNameShort = "Hacked", IsCheck = false
                            });
                        }
                        if (PluginDatabase.PluginSettings.EnableSteam)
                        {
                            icon = TransformIcon.Get("Steam") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Steam", SourceNameShort = "Steam", IsCheck = false
                            });
                        }
                        if (PluginDatabase.PluginSettings.EnableGog)
                        {
                            icon = TransformIcon.Get("GOG") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "GOG", SourceNameShort = "GOG", IsCheck = false
                            });
                        }
                        if (PluginDatabase.PluginSettings.EnableOrigin)
                        {
                            icon = TransformIcon.Get("Origin") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Origin", SourceNameShort = "Origin", IsCheck = false
                            });
                        }
                        if (PluginDatabase.PluginSettings.EnableXbox)
                        {
                            icon = TransformIcon.Get("Xbox") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Xbox", SourceNameShort = "Xbox", IsCheck = false
                            });
                        }
                        if (PluginDatabase.PluginSettings.EnableRetroAchievements)
                        {
                            icon = TransformIcon.Get("RetroAchievements") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "RetroAchievements", SourceNameShort = "RetroAchievements", IsCheck = false
                            });
                        }
                        if (PluginDatabase.PluginSettings.EnableRpcs3Achievements)
                        {
                            icon = TransformIcon.Get("RPCS3") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "RPCS3", SourceNameShort = "Rpcs3", IsCheck = false
                            });
                        }
                        if (PluginDatabase.PluginSettings.EnableManual)
                        {
                            icon = TransformIcon.Get("Manual") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Manual", SourceNameShort = "Manual", IsCheck = false
                            });
                        }
                    }

                    FilterSource.ItemsSource = FilterSourceItems;


                    // Set Binding data
                    DataContext = this;

                    PART_DataLoad.Visibility = Visibility.Hidden;
                    PART_Data.Visibility     = Visibility.Visible;
                });
            });
        }
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        public void GetListGame()
        {
            string pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            try
            {
                if (ListGames.Count == 0)
                {
                    var dataGameAchievements = PluginDatabase.Database.Where(x => x.HaveAchivements && x.IsDeleted == false);
                    foreach (GameAchievements item in dataGameAchievements)
                    {
                        string SourceName = PlayniteTools.GetSourceName(_PlayniteApi, item.Id);

                        string   GameId           = item.Id.ToString();
                        string   GameName         = item.Name;
                        string   GameIcon         = string.Empty;
                        string   Icon100          = string.Empty;
                        DateTime?GameLastActivity = null;

                        GameAchievements successStories = PluginDatabase.Get(item.Id);

                        if (item.LastActivity != null)
                        {
                            GameLastActivity = ((DateTime)item.LastActivity).ToLocalTime();
                        }

                        if (!item.Icon.IsNullOrEmpty())
                        {
                            GameIcon = _PlayniteApiDatabase.GetFullFilePath(item.Icon);
                        }

                        if (successStories.Is100Percent)
                        {
                            Icon100 = Path.Combine(pluginFolder, "Resources\\badge.png");
                        }

                        ListGames.Add(new ListViewGames()
                        {
                            Icon100Percent   = Icon100,
                            Id               = GameId,
                            Name             = GameName,
                            Icon             = GameIcon,
                            LastActivity     = GameLastActivity,
                            SourceName       = SourceName,
                            SourceIcon       = TransformIcon.Get(SourceName),
                            ProgressionValue = successStories.Progression,
                            Total            = successStories.Total,
                            TotalPercent     = successStories.Progression + "%",
                            Unlocked         = successStories.Unlocked,
                            IsManual         = successStories.IsManual
                        });
                    }

#if DEBUG
                    logger.Debug($"SuccessStory [Ignored] - ListGames: {JsonConvert.SerializeObject(ListGames)}");
#endif
                }

                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                {
                    ListviewGames.ItemsSource = ListGames;
                    Sorting();
                });
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SuccessStory", "Errorn on GetListGames()");
            }
        }
        /// <summary>
        /// Get data graphic activity by month with time by source or by genre.
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        public void getActivityByMonth(int year, int month)
        {
            DateTime startOfMonth = new DateTime(year, month, 1, 0, 0, 0);
            DateTime endOfMonth   = new DateTime(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59);

            JObject activityByMonth = new JObject();

            // Total hours by source.
            if (isMonthSources)
            {
                List <GameActivityClass> listGameActivities = GameActivityDatabases.GetListGameActivity();
                for (int iGame = 0; iGame < listGameActivities.Count; iGame++)
                {
                    try
                    {
                        List <Activity> gameActivities = listGameActivities[iGame].Activities;
                        for (int iActivity = 0; iActivity < gameActivities.Count; iActivity++)
                        {
                            long     elapsedSeconds = gameActivities[iActivity].ElapsedSeconds;
                            DateTime dateSession    = Convert.ToDateTime(gameActivities[iActivity].DateSession).AddSeconds(-elapsedSeconds).ToLocalTime();
                            string   sourceName     = gameActivities[iActivity].SourceName;

                            // Cumul data
                            if (activityByMonth[sourceName] != null)
                            {
                                if (startOfMonth <= dateSession && dateSession <= endOfMonth)
                                {
                                    activityByMonth[sourceName] = (long)activityByMonth[sourceName] + elapsedSeconds;
                                }
                            }
                            else
                            {
                                if (startOfMonth <= dateSession && dateSession <= endOfMonth)
                                {
                                    activityByMonth.Add(new JProperty(sourceName, elapsedSeconds));
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Common.LogError(ex, "GameActivity", $"Error in getActivityByMonth({year}, {month}) with {listGameActivities[iGame].GameName}");
                    }
                }

                gridMonth.Width      = 605;
                acwSeries.Visibility = Visibility.Visible;
                acwLabel.Visibility  = Visibility.Visible;
            }
            // Total hours by genres.
            else
            {
                List <GameActivityClass> listGameActivities = GameActivityDatabases.GetListGameActivity();
                for (int iGame = 0; iGame < listGameActivities.Count; iGame++)
                {
                    try
                    {
                        List <Genre>    listGameListGenres = listGameActivities[iGame].Genres;
                        List <Activity> gameActivities     = listGameActivities[iGame].Activities;
                        for (int iActivity = 0; iActivity < gameActivities.Count; iActivity++)
                        {
                            long     elapsedSeconds = gameActivities[iActivity].ElapsedSeconds;
                            DateTime dateSession    = Convert.ToDateTime(gameActivities[iActivity].DateSession).AddSeconds(-elapsedSeconds).ToLocalTime();

                            for (int iGenre = 0; iGenre < listGameListGenres.Count; iGenre++)
                            {
                                // Cumul data
                                if (activityByMonth[listGameListGenres[iGenre].Name] != null)
                                {
                                    if (startOfMonth <= dateSession && dateSession <= endOfMonth)
                                    {
                                        activityByMonth[listGameListGenres[iGenre].Name] = (long)activityByMonth[listGameListGenres[iGenre].Name] + elapsedSeconds;
                                    }
                                }
                                else
                                {
                                    if (startOfMonth <= dateSession && dateSession <= endOfMonth)
                                    {
                                        activityByMonth.Add(new JProperty(listGameListGenres[iGenre].Name, elapsedSeconds));
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Common.LogError(ex, "GameActivity", $"Error in getActivityByMonth({year}, {month}) with {listGameActivities[iGame].GameName}");
                    }
                }

                gridMonth.Width      = 1223;
                acwSeries.Visibility = Visibility.Hidden;
                acwLabel.Visibility  = Visibility.Hidden;
            }


            // Set data in graphic.
            ChartValues <CustomerForTime> series = new ChartValues <CustomerForTime>();

            string[] labels   = new string[activityByMonth.Count];
            int      compteur = 0;

            foreach (var item in activityByMonth)
            {
                series.Add(new CustomerForTime
                {
                    Name   = item.Key,
                    Values = (long)item.Value,
                });
                labels[compteur] = item.Key;
                if (settings.showLauncherIcons)
                {
                    labels[compteur] = TransformIcon.Get(labels[compteur]);
                }
                compteur = compteur + 1;
            }

            SeriesCollection ActivityByMonthSeries = new SeriesCollection
            {
                new ColumnSeries
                {
                    Title  = "",
                    Values = series
                }
            };

            string[] ActivityByMonthLabels = labels;

            //let create a mapper so LiveCharts know how to plot our CustomerViewModel class
            var customerVmMapper = Mappers.Xy <CustomerForTime>()
                                   .X((value, index) => index)
                                   .Y(value => value.Values);

            //lets save the mapper globally
            Charting.For <CustomerForTime>(customerVmMapper);

            Func <double, string> activityForGameLogFormatter = value => (string)converter.Convert((long)value, null, null, CultureInfo.CurrentCulture);

            acmLabelsY.LabelFormatter = activityForGameLogFormatter;

            acmSeries.Series    = ActivityByMonthSeries;
            acmLabelsY.MinValue = 0;
            ((CustomerToolTipForTime)acmSeries.DataTooltip).ShowIcon = settings.showLauncherIcons;
            acmLabelsX.Labels = ActivityByMonthLabels;
        }
        /// <summary>
        /// Get data graphic activity by week.
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        public void getActivityByWeek(int year, int month)
        {
            //https://www.codeproject.com/Questions/1276907/Get-every-weeks-start-and-end-date-from-series-end
            //usage:
            DateTime StartDate     = new DateTime(year, month, 1, 0, 0, 0);
            DateTime SeriesEndDate = new DateTime(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59);
            //find first monday
            DateTime firstMonday = Enumerable.Range(0, 7)
                                   .SkipWhile(x => StartDate.AddDays(x).DayOfWeek != DayOfWeek.Monday)
                                   .Select(x => StartDate.AddDays(x))
                                   .First();
            //get count of days
            TimeSpan ts = (TimeSpan)(SeriesEndDate - firstMonday);
            //create new list of WeekStartEnd class
            List <WeekStartEnd> datesPeriodes = new List <WeekStartEnd>();

            //add dates to list
            for (int i = 0; i < ts.Days; i += 7)
            {
                datesPeriodes.Add(new WeekStartEnd()
                {
                    Monday = firstMonday.AddDays(i), Sunday = firstMonday.AddDays(i + 6).AddHours(23).AddMinutes(59).AddSeconds(59)
                });
            }

            // Source activty by month
            JObject activityByWeek1 = new JObject();
            JObject activityByWeek2 = new JObject();
            JObject activityByWeek3 = new JObject();
            JObject activityByWeek4 = new JObject();
            JObject activityByWeek5 = new JObject();

            JArray           activityByWeek       = new JArray();
            SeriesCollection activityByWeekSeries = new SeriesCollection();

            if (isMonthSources)
            {
                // Insert sources
                for (int iSource = 0; iSource < listSources.Count; iSource++)
                {
                    activityByWeek1.Add((string)listSources[iSource], 0);
                    activityByWeek2.Add((string)listSources[iSource], 0);
                    activityByWeek3.Add((string)listSources[iSource], 0);
                    activityByWeek4.Add((string)listSources[iSource], 0);
                    activityByWeek5.Add((string)listSources[iSource], 0);
                }

                activityByWeek.Add(activityByWeek1);
                activityByWeek.Add(activityByWeek2);
                activityByWeek.Add(activityByWeek3);
                activityByWeek.Add(activityByWeek4);
                activityByWeek.Add(activityByWeek5);

                List <GameActivityClass> listGameActivities = GameActivityDatabases.GetListGameActivity();
                for (int iGame = 0; iGame < listGameActivities.Count; iGame++)
                {
                    List <Activity> gameActivities = listGameActivities[iGame].Activities;
                    for (int iActivity = 0; iActivity < gameActivities.Count; iActivity++)
                    {
                        long     elapsedSeconds = gameActivities[iActivity].ElapsedSeconds;
                        DateTime dateSession    = Convert.ToDateTime(gameActivities[iActivity].DateSession).AddSeconds(-elapsedSeconds).ToLocalTime();
                        string   sourceName     = gameActivities[iActivity].SourceName;

                        // Cumul data
                        for (int iWeek = 0; iWeek < datesPeriodes.Count; iWeek++)
                        {
                            if (datesPeriodes[iWeek].Monday <= dateSession && dateSession <= datesPeriodes[iWeek].Sunday)
                            {
                                activityByWeek[iWeek][sourceName] = (long)activityByWeek[iWeek][sourceName] + elapsedSeconds;
                            }
                        }
                    }
                }


                // Check source with data (only view this)
                JArray listNoDelete = new JArray();
                for (int i = 0; i < activityByWeek.Count; i++)
                {
                    foreach (var item in (JObject)activityByWeek[i])
                    {
                        if ((long)item.Value != 0 && listNoDelete.TakeWhile(x => x.ToString() == item.Key).Count() != 1)
                        {
                            listNoDelete.Add(item.Key);
                        }
                    }
                }
                listNoDelete = JArray.FromObject(listNoDelete.Distinct().ToArray());


                // Prepare data.
                string[] labels = new string[listNoDelete.Count];
                for (int iSource = 0; iSource < listNoDelete.Count; iSource++)
                {
                    labels[iSource] = (string)listNoDelete[iSource];
                    if (settings.showLauncherIcons)
                    {
                        labels[iSource] = TransformIcon.Get((string)listNoDelete[iSource]);
                    }

                    IChartValues Values = new ChartValues <CustomerForTime>()
                    {
                        new CustomerForTime {
                            Name = (string)listNoDelete[iSource], Values = (int)activityByWeek[0][(string)listNoDelete[iSource]]
                        },
                        new CustomerForTime {
                            Name = (string)listNoDelete[iSource], Values = (int)activityByWeek[1][(string)listNoDelete[iSource]]
                        },
                        new CustomerForTime {
                            Name = (string)listNoDelete[iSource], Values = (int)activityByWeek[2][(string)listNoDelete[iSource]]
                        },
                        new CustomerForTime {
                            Name = (string)listNoDelete[iSource], Values = (int)activityByWeek[3][(string)listNoDelete[iSource]]
                        }
                    };

                    if (datesPeriodes.Count == 5)
                    {
                        Values.Add(new CustomerForTime {
                            Name = (string)listNoDelete[iSource], Values = (int)activityByWeek[4][(string)listNoDelete[iSource]]
                        });
                    }

                    activityByWeekSeries.Add(new StackedColumnSeries
                    {
                        Title      = labels[iSource],
                        Values     = Values,
                        StackMode  = StackMode.Values,
                        DataLabels = false
                    });
                }
            }


            // Set data in graphics.
            string[] activityByWeekLabels = new[]
            {
                resources.GetString("LOCGameActivityWeekLabel") + " " + Tools.WeekOfYearISO8601(datesPeriodes[0].Monday),
                resources.GetString("LOCGameActivityWeekLabel") + " " + Tools.WeekOfYearISO8601(datesPeriodes[1].Monday),
                resources.GetString("LOCGameActivityWeekLabel") + " " + Tools.WeekOfYearISO8601(datesPeriodes[2].Monday),
                resources.GetString("LOCGameActivityWeekLabel") + " " + Tools.WeekOfYearISO8601(datesPeriodes[3].Monday)
            };
            if (datesPeriodes.Count == 5)
            {
                activityByWeekLabels = new[]
                {
                    resources.GetString("LOCGameActivityWeekLabel") + " " + Tools.WeekOfYearISO8601(datesPeriodes[0].Monday),
                    resources.GetString("LOCGameActivityWeekLabel") + " " + Tools.WeekOfYearISO8601(datesPeriodes[1].Monday),
                    resources.GetString("LOCGameActivityWeekLabel") + " " + Tools.WeekOfYearISO8601(datesPeriodes[2].Monday),
                    resources.GetString("LOCGameActivityWeekLabel") + " " + Tools.WeekOfYearISO8601(datesPeriodes[3].Monday),
                    resources.GetString("LOCGameActivityWeekLabel") + " " + Tools.WeekOfYearISO8601(datesPeriodes[4].Monday)
                };
            }


            //let create a mapper so LiveCharts know how to plot our CustomerViewModel class
            var customerVmMapper = Mappers.Xy <CustomerForTime>()
                                   .X((value, index) => index)
                                   .Y(value => value.Values);

            //lets save the mapper globally
            Charting.For <CustomerForTime>(customerVmMapper);

            Func <double, string> activityForGameLogFormatter = value => (string)converter.Convert((long)value, null, null, CultureInfo.CurrentCulture);

            acwLabelsY.LabelFormatter = activityForGameLogFormatter;

            acwSeries.Series    = activityByWeekSeries;
            acwLabelsY.MinValue = 0;
            ((CustomerToolTipForMultipleTime)acwSeries.DataTooltip).ShowIcon = settings.showLauncherIcons;
            acwLabelsX.Labels = activityByWeekLabels;
        }
        private void LoadData(IPlayniteAPI PlayniteApi)
        {
            listGameScreenshots = new List <ListGameScreenshot>();
            foreach (var item in ScreenshotsVisualizer.PluginDatabase.PluginSettings.Settings.gameSettings)
            {
                Game game = PlayniteApi.Database.Games.Get(item.Id);

                if (game != null)
                {
                    string Icon = string.Empty;
                    if (!game.Icon.IsNullOrEmpty())
                    {
                        Icon = PlayniteApi.Database.GetFullFilePath(game.Icon);
                    }

                    // TEMP
                    List <FolderSettings> ScreenshotsFolders = new List <FolderSettings>();
                    if (!item.ScreenshotsFolder.IsNullOrEmpty())
                    {
                        ScreenshotsFolders.Add(new FolderSettings
                        {
                            UsedFilePattern   = item.UsedFilePattern,
                            FilePattern       = item.FilePattern,
                            ScreenshotsFolder = item.ScreenshotsFolder,
                            ScanSubFolders    = item.ScanSubFolders
                        });
                    }
                    else
                    {
                        ScreenshotsFolders = item.ScreenshotsFolders;
                    }

                    listGameScreenshots.Add(new ListGameScreenshot
                    {
                        Id   = item.Id,
                        Icon = Icon,
                        Name = game.Name,
                        ScreenshotsFolders = ScreenshotsFolders,
                        UsedFilePattern    = item.UsedFilePattern,
                        ScanSubFolders     = item.ScanSubFolders,
                        FilePattern        = item.FilePattern,
                        SourceName         = PlayniteTools.GetSourceName(item.Id),
                        SourceIcon         = TransformIcon.Get(PlayniteTools.GetSourceName(item.Id))
                    });
                }
                else
                {
                    logger.Warn($"Game is deleted - {item.Id}");
                }
            }

            var DbWithoutAlready = PlayniteApi.Database.Games.Where(x => !listGameScreenshots.Any(y => x.Id == y.Id));

            listGames = new List <ListGame>();
            foreach (Game item in DbWithoutAlready)
            {
                string Icon = string.Empty;
                if (!item.Icon.IsNullOrEmpty())
                {
                    Icon = PlayniteApi.Database.GetFullFilePath(item.Icon);
                }

                listGames.Add(new ListGame
                {
                    Id         = item.Id,
                    Icon       = Icon,
                    Name       = item.Name,
                    SourceName = PlayniteTools.GetSourceName(item.Id),
                    SourceIcon = TransformIcon.Get(PlayniteTools.GetSourceName(item.Id))
                });
            }

            listGames.Sort((x, y) => x.Name.CompareTo(y.Name));
            listGameScreenshots.Sort((x, y) => x.Name.CompareTo(y.Name));
        }
Ejemplo n.º 20
0
        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;
                });
            });
        }
Ejemplo n.º 21
0
        /// <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 AchievementsGraphicsDataCountSources GetCountBySources()
        {
            List <string> tempSourcesLabels = new List <string>();

            if (Settings.EnableGog)
            {
                tempSourcesLabels.Add("GOG");
            }
            if (Settings.EnableSteam)
            {
                tempSourcesLabels.Add("Steam");
            }
            if (Settings.EnableOrigin)
            {
                tempSourcesLabels.Add("Origin");
            }
            if (Settings.EnableRetroAchievements)
            {
                tempSourcesLabels.Add("RetroAchievements");
            }
            if (Settings.EnableLocal)
            {
                tempSourcesLabels.Add("Playnite");
            }
            tempSourcesLabels.Sort((x, y) => x.CompareTo(y));

            string[] GraphicsAchievementsLabels = new string[tempSourcesLabels.Count];
            List <AchievementsGraphicsDataSources> tempDataUnlocked = new List <AchievementsGraphicsDataSources>();
            List <AchievementsGraphicsDataSources> tempDataLocked   = new List <AchievementsGraphicsDataSources>();
            List <AchievementsGraphicsDataSources> tempDataTotal    = new List <AchievementsGraphicsDataSources>();

            for (int i = 0; i < tempSourcesLabels.Count; i++)
            {
                GraphicsAchievementsLabels[i] = TransformIcon.Get(tempSourcesLabels[i]);
                tempDataLocked.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
                tempDataUnlocked.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
                tempDataTotal.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
            }


            List <Guid> ListEmulators = new List <Guid>();

            foreach (var item in PlayniteApi.Database.Emulators)
            {
                ListEmulators.Add(item.Id);
            }


            foreach (var item in PluginDatabase)
            {
                Game   game       = PlayniteApi.Database.Games.Get(item.Key);
                string SourceName = "";
                if (game.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                {
                    SourceName = game.Source.Name;

                    if (game.PlayAction != null && game.PlayAction.EmulatorId != null && ListEmulators.Contains(game.PlayAction.EmulatorId))
                    {
                        SourceName = "RetroAchievements";
                    }
                }
                else
                {
                    if (game.PlayAction != null && game.PlayAction.EmulatorId != null && ListEmulators.Contains(game.PlayAction.EmulatorId))
                    {
                        SourceName = "RetroAchievements";
                    }
                    else
                    {
                        SourceName = "Playnite";
                    }
                }

                foreach (Achievements achievements in item.Value.Achievements)
                {
                    for (int i = 0; i < tempDataUnlocked.Count; i++)
                    {
                        if (tempDataUnlocked[i].source == SourceName)
                        {
                            tempDataTotal[i].value += 1;
                            if (achievements.DateUnlocked != default(DateTime))
                            {
                                tempDataUnlocked[i].value += 1;
                            }
                            if (achievements.DateUnlocked == default(DateTime))
                            {
                                tempDataLocked[i].value += 1;
                            }
                        }
                    }
                }
            }

            ChartValues <CustomerForSingle> SourceAchievementsSeriesUnlocked = new ChartValues <CustomerForSingle>();
            ChartValues <CustomerForSingle> SourceAchievementsSeriesLocked   = new ChartValues <CustomerForSingle>();
            ChartValues <CustomerForSingle> SourceAchievementsSeriesTotal    = new ChartValues <CustomerForSingle>();

            for (int i = 0; i < tempDataUnlocked.Count; i++)
            {
                SourceAchievementsSeriesUnlocked.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataUnlocked[i].source),
                    Values = tempDataUnlocked[i].value
                });
                SourceAchievementsSeriesLocked.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataLocked[i].source),
                    Values = tempDataLocked[i].value
                });
                SourceAchievementsSeriesTotal.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataTotal[i].source),
                    Values = tempDataTotal[i].value
                });
            }


            return(new AchievementsGraphicsDataCountSources
            {
                Labels = GraphicsAchievementsLabels,
                SeriesLocked = SourceAchievementsSeriesLocked,
                SeriesUnlocked = SourceAchievementsSeriesUnlocked,
                SeriesTotal = SourceAchievementsSeriesTotal
            });
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        public void GetListGame()
        {
            List <Guid> ListEmulators = new List <Guid>();

            foreach (var item in PlayniteApi.Database.Emulators)
            {
                ListEmulators.Add(item.Id);
            }

            if (ListGames.Count == 0)
            {
                foreach (var item in PlayniteApiDatabase.Games)
                {
                    string GameSourceName = "";
                    if (item.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                    {
                        GameSourceName = item.Source.Name;

                        if (item.PlayAction != null && item.PlayAction.EmulatorId != null && ListEmulators.Contains(item.PlayAction.EmulatorId))
                        {
                            GameSourceName = "RetroAchievements";
                        }
                    }
                    else
                    {
                        if (item.PlayAction != null && item.PlayAction.EmulatorId != null && ListEmulators.Contains(item.PlayAction.EmulatorId))
                        {
                            GameSourceName = "RetroAchievements";
                        }
                        else
                        {
                            GameSourceName = "Playnite";
                        }
                    }

                    if (AchievementsDatabase.HaveAchievements(item.Id))
                    {
                        if (AchievementsDatabase.VerifToAddOrShow(GameSourceName, settings, PluginUserDataPath))
                        {
                            string   GameId   = item.Id.ToString();
                            string   GameName = item.Name;
                            string   GameIcon;
                            DateTime?GameLastActivity = null;

                            string SourceName = "";
                            if (item.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                            {
                                SourceName = item.Source.Name;

                                if (item.PlayAction != null && item.PlayAction.EmulatorId != null && ListEmulators.Contains(item.PlayAction.EmulatorId))
                                {
                                    SourceName = "RetroAchievements";
                                }
                            }
                            else
                            {
                                if (item.PlayAction != null && item.PlayAction.EmulatorId != null && ListEmulators.Contains(item.PlayAction.EmulatorId))
                                {
                                    SourceName = "RetroAchievements";
                                }
                                else
                                {
                                    SourceName = "Playnite";
                                }
                            }

                            GameAchievements GameAchievements = AchievementsDatabase.Get(item.Id);

                            if (item.LastActivity != null)
                            {
                                GameLastActivity = ((DateTime)item.LastActivity).ToLocalTime();
                            }

                            BitmapImage iconImage = new BitmapImage();
                            if (String.IsNullOrEmpty(item.Icon) == false)
                            {
                                iconImage.BeginInit();
                                GameIcon            = PlayniteApiDatabase.GetFullFilePath(item.Icon);
                                iconImage.UriSource = new Uri(GameIcon, UriKind.RelativeOrAbsolute);
                                iconImage.EndInit();
                            }

                            ListGames.Add(new ListGames()
                            {
                                Id               = GameId,
                                Name             = GameName,
                                Icon             = iconImage,
                                LastActivity     = GameLastActivity,
                                SourceName       = SourceName,
                                SourceIcon       = TransformIcon.Get(SourceName),
                                ProgressionValue = GameAchievements.Progression,
                                Total            = GameAchievements.Total,
                                TotalPercent     = GameAchievements.Progression + "%",
                                Unlocked         = GameAchievements.Unlocked
                            });

                            iconImage = null;
                        }
                    }
                }
            }


            ListviewGames.ItemsSource = ListGames;
            // Filter
            if (!TextboxSearch.Text.IsNullOrEmpty() && SearchSources.Count != 0)
            {
                ListviewGames.ItemsSource = ListGames.FindAll(
                    x => x.Name.ToLower().IndexOf(TextboxSearch.Text) > -1 && SearchSources.Contains(x.SourceName)
                    );
                return;
            }

            if (!TextboxSearch.Text.IsNullOrEmpty())
            {
                ListviewGames.ItemsSource = ListGames.FindAll(
                    x => x.Name.ToLower().IndexOf(TextboxSearch.Text) > -1
                    );
                return;
            }

            if (SearchSources.Count != 0)
            {
                ListviewGames.ItemsSource = ListGames.FindAll(
                    x => SearchSources.Contains(x.SourceName)
                    );
                return;
            }


            // Sorting
            try
            {
                var columnBinding = _lastHeaderClicked.Column.DisplayMemberBinding as Binding;
                var sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;

                // Specific sort with another column
                if (_lastHeaderClicked.Name == "lvSourceIcon")
                {
                    columnBinding = lvSourceName.Column.DisplayMemberBinding as Binding;
                    sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;
                }
                if (_lastHeaderClicked.Name == "lvProgression")
                {
                    columnBinding = lvProgressionValue.Column.DisplayMemberBinding as Binding;
                    sortBy        = columnBinding?.Path.Path ?? _lastHeaderClicked.Column.Header as string;
                }
                Sort(sortBy, _lastDirection);
            }
            // If first view
            catch
            {
                CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(ListviewGames.ItemsSource);

                switch (settings.NameSorting)
                {
                case ("Name"):
                    _lastHeaderClicked = lvName;
                    if (settings.IsAsc)
                    {
                        _lastHeaderClicked.Content += " ▲";
                    }
                    else
                    {
                        _lastHeaderClicked.Content += " ▼";
                    }
                    break;

                case ("LastActivity"):
                    _lastHeaderClicked = lvLastActivity;
                    if (settings.IsAsc)
                    {
                        _lastHeaderClicked.Content += " ▲";
                    }
                    else
                    {
                        _lastHeaderClicked.Content += " ▼";
                    }
                    break;

                case ("SourceName"):
                    _lastHeaderClicked = lvSourceIcon;
                    if (settings.IsAsc)
                    {
                        lvSourceIcon.Content += " ▲";
                    }
                    else
                    {
                        lvSourceIcon.Content += " ▼";
                    }
                    break;

                case ("ProgressionValue"):
                    _lastHeaderClicked = lvProgression;
                    if (settings.IsAsc)
                    {
                        lvProgression.Content += " ▲";
                    }
                    else
                    {
                        lvProgression.Content += " ▼";
                    }
                    break;
                }


                if (settings.IsAsc)
                {
                    _lastDirection = ListSortDirection.Ascending;
                }
                else
                {
                    _lastDirection = ListSortDirection.Descending;
                }


                view.SortDescriptions.Add(new SortDescription(settings.NameSorting, _lastDirection));
            }
        }